Skip to content

Commit 48a5346

Browse files
committed
fix: resolved coderabbit suggested chnages
Signed-off-by: Rinkal Bhojani <[email protected]>
1 parent cbcaae9 commit 48a5346

File tree

6 files changed

+47
-20
lines changed

6 files changed

+47
-20
lines changed

apps/api-gateway/src/agent-service/dto/create-schema.dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export class CreateTenantSchemaDto {
2121
@IsArray({ message: 'attributes must be an array' })
2222
@IsString({ each: true })
2323
// TODO: IsNotEmpty won't work for array. Must use @ArrayNotEmpty() instead
24+
// @ArrayNotEmpty({ message: 'please provide at least one attribute' })
25+
// @IsNotEmpty({ each: true, message: 'attribute must not be empty' })
2426
@IsNotEmpty({ message: 'please provide valid attributes' })
2527
attributes: string[];
2628

apps/api-gateway/src/oid4vc-issuance/dtos/issuer-sessions.dto.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
ValidatorConstraint,
1818
ValidatorConstraintInterface,
1919
ValidationArguments,
20-
Validate
20+
Validate,
21+
IsDate
2122
} from 'class-validator';
2223
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2324
import { Type } from 'class-transformer';
@@ -123,16 +124,18 @@ export class ValidityInfo {
123124
example: '2025-04-23T14:34:09.188Z',
124125
required: true
125126
})
126-
@IsString()
127127
@IsNotEmpty()
128+
@Type(() => Date)
129+
@IsDate()
128130
validFrom: Date;
129131

130132
@ApiProperty({
131133
example: '2026-05-03T14:34:09.188Z',
132134
required: true
133135
})
134-
@IsString()
135136
@IsNotEmpty()
137+
@Type(() => Date)
138+
@IsDate()
136139
validUntil: Date;
137140
}
138141

apps/api-gateway/src/oid4vc-issuance/dtos/oid4vc-issuer-template.dto.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { ApiExtraModels, ApiProperty, ApiPropertyOptional, getSchemaPath, PartialType } from '@nestjs/swagger';
1616
import { Type } from 'class-transformer';
1717
import { SignerOption } from '@prisma/client';
18-
import { CredentialFormat } from '@credebl/enum/enum';
18+
import { AttributeType, CredentialFormat } from '@credebl/enum/enum';
1919

2020
class CredentialAttributeDisplayDto {
2121
@ApiPropertyOptional({ example: 'First Name' })
@@ -28,17 +28,6 @@ class CredentialAttributeDisplayDto {
2828
@IsOptional()
2929
locale?: string;
3030
}
31-
32-
export enum AttributeType {
33-
STRING = 'string',
34-
NUMBER = 'number',
35-
BOOLEAN = 'boolean',
36-
DATE = 'date',
37-
OBJECT = 'object',
38-
ARRAY = 'array',
39-
IMAGE = 'image'
40-
}
41-
4231
export class CredentialAttributeDto {
4332
@ApiProperty({ description: 'Unique key for this attribute (e.g., full_name, org.iso.23220.photoID.1.birth_date)' })
4433
@IsString()
@@ -52,7 +41,8 @@ export class CredentialAttributeDto {
5241
// TODO: Check how do we handle claims with only path rpoperty like email, etc.
5342
@ApiProperty({ enum: AttributeType, description: 'Type of the attribute value (string, number, date, etc.)' })
5443
@IsEnum(AttributeType)
55-
value_type: string;
44+
// TODO: changes value_type: AttributeType;
45+
value_type: AttributeType;
5646

5747
@ApiProperty({ description: 'Whether this attribute should be disclosed (for SD-JWT)' })
5848
@IsOptional()
@@ -210,6 +200,8 @@ export class SdJwtTemplateDto {
210200
description: 'Attributes included in the credential template'
211201
})
212202
@IsArray()
203+
@ValidateNested({ each: true })
204+
@Type(() => CredentialAttributeDto)
213205
attributes: CredentialAttributeDto[];
214206
}
215207

apps/oid4vc-issuance/interfaces/oid4vc-template.interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Prisma, SignerOption } from '@prisma/client';
2-
import { CredentialFormat } from '@credebl/enum/enum';
2+
import { AttributeType, CredentialFormat } from '@credebl/enum/enum';
33
export interface SdJwtTemplate {
44
vct: string;
55
attributes: CredentialAttribute[];
@@ -40,7 +40,7 @@ export interface Claim {
4040
export interface CredentialAttribute {
4141
key: string;
4242
mandatory?: boolean;
43-
value_type: string;
43+
value_type: AttributeType;
4444
disclose?: boolean;
4545
children?: CredentialAttribute[];
4646
display?: ClaimDisplay[];

libs/common/src/date-only.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,25 @@ const customInspectSymbol = Symbol.for('nodejs.util.inspect.custom');
22
export class DateOnly {
33
private date: Date;
44

5-
public constructor(date?: string) {
6-
this.date = date ? new Date(date) : new Date();
5+
public constructor(date?: string | Date) {
6+
if (date instanceof Date) {
7+
if (isNaN(date.getTime())) {
8+
throw new TypeError('Invalid Date');
9+
}
10+
this.date = date;
11+
return;
12+
}
13+
if (!date) {
14+
this.date = new Date();
15+
return;
16+
}
17+
// Accept only YYYY-MM-DD or full ISO strings
18+
const iso = /^\d{4}-\d{2}-\d{2}(T.*Z)?$/.test(date) ? date : '';
19+
const d = new Date(iso || date);
20+
if (isNaN(d.getTime())) {
21+
throw new TypeError('Invalid date string');
22+
}
23+
this.date = d;
724
}
825

926
get [Symbol.toStringTag](): string {
@@ -34,5 +51,8 @@ export const serverStartupTimeInMilliseconds = Date.now();
3451

3552
export function dateToSeconds(date: Date | DateOnly): number {
3653
const realDate = date instanceof DateOnly ? new Date(date.toISOString()) : date;
54+
if (isNaN(realDate.getTime())) {
55+
throw new TypeError('dateToSeconds: invalid date');
56+
}
3757
return Math.floor(realDate.getTime() / 1000);
3858
}

libs/enum/src/enum.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,16 @@ export enum CredentialFormat {
323323
Mdoc = 'mso_mdoc'
324324
}
325325

326+
export enum AttributeType {
327+
STRING = 'string',
328+
NUMBER = 'number',
329+
BOOLEAN = 'boolean',
330+
DATE = 'date',
331+
OBJECT = 'object',
332+
ARRAY = 'array',
333+
IMAGE = 'image'
334+
}
335+
326336
// export enum SignerOption {
327337
// DID,
328338
// X509_P256,

0 commit comments

Comments
 (0)