generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ORV2-2073 Shopping Cart APIs (#1320)
Co-authored-by: praju-aot <[email protected]>
- Loading branch information
1 parent
7d4b130
commit ba076e0
Showing
14 changed files
with
698 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,3 @@ ELSE BEGIN | |
PRINT 'The database update failed' | ||
END | ||
GO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
vehicles/src/modules/shopping-cart/dto/request/add-to-shopping-cart.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { ArrayMinSize, IsNumberString } from 'class-validator'; | ||
|
||
/** | ||
* DTO (Data Transfer Object) for creating a shopping cart. | ||
* It includes the necessary properties and validations for the creation process. | ||
* | ||
* @property {string[]} applicationIds - Application Ids to be added to the cart. Should be an array of number strings without symbols. | ||
*/ | ||
export class AddToShoppingCartDto { | ||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'Application Ids to be added to the cart.', | ||
isArray: true, | ||
type: String, | ||
example: ['74'], | ||
}) | ||
@ArrayMinSize(1) | ||
@IsNumberString({ no_symbols: true }, { each: true }) | ||
applicationIds: string[]; | ||
} |
14 changes: 14 additions & 0 deletions
14
vehicles/src/modules/shopping-cart/dto/request/pathParam/companyId.path-param.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Type } from 'class-transformer'; | ||
import { IsInt, IsPositive } from 'class-validator'; | ||
|
||
export class CompanyIdPathParamDto { | ||
@ApiProperty({ | ||
description: `Id of the company the cart belongs to.`, | ||
example: 74, | ||
}) | ||
@IsInt() | ||
@IsPositive() | ||
@Type(() => Number) | ||
companyId: number; | ||
} |
3 changes: 3 additions & 0 deletions
3
vehicles/src/modules/shopping-cart/dto/request/update-shopping-cart.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { AddToShoppingCartDto } from './add-to-shopping-cart.dto'; | ||
|
||
export class UpdateShoppingCartDto extends AddToShoppingCartDto {} |
90 changes: 90 additions & 0 deletions
90
vehicles/src/modules/shopping-cart/dto/response/read-shopping-cart.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { ApplicationStatus } from '../../../../common/enum/application-status.enum'; | ||
import { PermitType } from '../../../../common/enum/permit-type.enum'; | ||
|
||
export class ReadShoppingCartDto { | ||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'Id of the company requesting the permit.', | ||
example: 74, | ||
}) | ||
companyId: number; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'Id of the application.', | ||
example: 74, | ||
}) | ||
applicationId: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
enum: PermitType, | ||
description: 'The permit type abbreviation.', | ||
example: PermitType.TERM_OVERSIZE, | ||
}) | ||
permitType: PermitType; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
example: 'A2-00000002-120', | ||
description: 'Unique formatted permit application number.', | ||
}) | ||
applicationNumber: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'Status of Permit/Permit Application', | ||
example: ApplicationStatus.IN_CART, | ||
required: false, | ||
}) | ||
permitStatus: ApplicationStatus.IN_CART; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'Application updated Date and Time.', | ||
}) | ||
updatedDateTime: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'Name of the applicant', | ||
example: 'John Smith', | ||
}) | ||
applicant: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'The userGUID of the applicant', | ||
example: 'S822OKE22LK', | ||
}) | ||
applicantGUID: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'The vehicle plate', | ||
example: 'S822OK', | ||
}) | ||
plate: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'The permit start date.', | ||
example: '2023-06-05T19:12:22Z', | ||
}) | ||
startDate: string; | ||
|
||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'The permit start date.', | ||
example: '2023-07-04T19:12:22Z', | ||
}) | ||
expiryDate: string; | ||
|
||
@ApiProperty({ | ||
description: 'The permit fee', | ||
example: 200, | ||
}) | ||
fee: number; | ||
} |
5 changes: 5 additions & 0 deletions
5
vehicles/src/modules/shopping-cart/dto/response/result.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class ResultDto { | ||
success: string[]; | ||
|
||
failure: string[]; | ||
} |
75 changes: 75 additions & 0 deletions
75
vehicles/src/modules/shopping-cart/profile/shopping-cart.profile.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { | ||
Mapper, | ||
createMap, | ||
forMember, | ||
mapFrom, | ||
mapWithArguments, | ||
} from '@automapper/core'; | ||
import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { UserAuthGroup } from '../../../common/enum/user-auth-group.enum'; | ||
import { getApplicantDisplay } from '../../../common/helper/permit-application.helper'; | ||
import { Permit as Application } from '../../permit-application-payment/permit/entities/permit.entity'; | ||
import { ReadShoppingCartDto } from '../dto/response/read-shopping-cart.dto'; | ||
import { PermitData } from '../../../common/interface/permit.template.interface'; | ||
|
||
@Injectable() | ||
export class ShoppingCartProfile extends AutomapperProfile { | ||
constructor(@InjectMapper() mapper: Mapper) { | ||
super(mapper); | ||
} | ||
|
||
override get profile() { | ||
return (mapper: Mapper) => { | ||
createMap( | ||
mapper, | ||
Application, | ||
ReadShoppingCartDto, | ||
forMember( | ||
(d) => d.companyId, | ||
mapWithArguments((_s, { companyId }) => companyId), | ||
), | ||
// permitId | ||
forMember( | ||
(d) => d.applicationId, | ||
mapFrom((s) => s?.permitId), | ||
), | ||
forMember( | ||
(d) => d.applicant, | ||
mapWithArguments((s, { currentUserAuthGroup }) => { | ||
return getApplicantDisplay( | ||
s.applicationOwner, | ||
currentUserAuthGroup as UserAuthGroup, | ||
); | ||
}), | ||
), | ||
forMember( | ||
(d) => d.applicantGUID, | ||
mapFrom((s) => s?.applicationOwner?.userGUID), | ||
), | ||
forMember( | ||
(d) => d.fee, | ||
mapFrom((s) => { | ||
const parsedPermitData = JSON.parse( | ||
s?.permitData?.permitData, | ||
) as PermitData; | ||
return +parsedPermitData?.feeSummary; | ||
}), | ||
), | ||
forMember( | ||
(d) => d.plate, | ||
mapFrom((s) => s?.permitData?.plate), | ||
), | ||
forMember( | ||
(d) => d.startDate, | ||
mapFrom((s) => s?.permitData?.startDate), | ||
), | ||
forMember( | ||
(d) => d.expiryDate, | ||
mapFrom((s) => s?.permitData?.expiryDate), | ||
), | ||
); | ||
}; | ||
} | ||
} |
Oops, something went wrong.