File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed
vehicles/src/modules/permit-application-payment/application Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ import {
3232 ApplicationQueueStatus ,
3333 convertApplicationQueueStatus ,
3434} from '../../../common/enum/case-status-type.enum' ;
35+ import { Param } from '@nestjs/common' ;
36+ import { ReadApplicationDto } from './dto/response/read-application.dto' ;
3537
3638@ApiBearerAuth ( )
3739@ApiTags ( 'Application : API accessible exclusively to staff users and SA.' )
@@ -115,4 +117,21 @@ export class ApplicationController {
115117 ) ;
116118 return result ;
117119 }
120+
121+ @ApiOperation ( {
122+ summary : 'Copy an issued permit into a new draft application' ,
123+ } )
124+ @Post ( '/:permitId/copy' )
125+ async copyPermit (
126+ @Req ( ) request : Request ,
127+ @Param ( 'permitId' ) permitId : string ,
128+ ) : Promise < ReadApplicationDto > {
129+ const currentUser = request . user as IUserJWT ;
130+
131+ return await this . applicationService . copyApplication (
132+ permitId ,
133+ currentUser ,
134+ currentUser . companyId ,
135+ ) ;
136+ }
118137}
Original file line number Diff line number Diff line change @@ -1387,4 +1387,49 @@ export class ApplicationService {
13871387 ) ;
13881388 return readPermitLoaDto ;
13891389 }
1390+
1391+ @LogAsyncMethodExecution ( )
1392+ async copyApplication (
1393+ permitId : string ,
1394+ currentUser : IUserJWT ,
1395+ companyId : number ,
1396+ ) : Promise < ReadApplicationDto > {
1397+ const original = await this . findOne ( permitId , companyId ) ;
1398+
1399+ if ( ! original ) {
1400+ throw new DataNotFoundException ( ) ;
1401+ }
1402+
1403+ if ( original . permitStatus !== ApplicationStatus . ISSUED ) {
1404+ throwUnprocessableEntityException ( 'Only issued permits can be copied.' ) ;
1405+ }
1406+
1407+ const originalData = JSON . parse (
1408+ original . permitData . permitData ,
1409+ ) as PermitData ;
1410+
1411+ const today = dayjs ( ) . format ( 'YYYY-MM-DD' ) ;
1412+
1413+ const duration = differenceBetween (
1414+ originalData . startDate ,
1415+ originalData . expiryDate ,
1416+ 'days' ,
1417+ ) ;
1418+ originalData . startDate = today ;
1419+ originalData . expiryDate = dayjs ( today )
1420+ . add ( duration , 'day' )
1421+ . format ( 'YYYY-MM-DD' ) ;
1422+
1423+ const createDto : CreateApplicationDto = {
1424+ permitType : original . permitType ,
1425+ permitId : null ,
1426+ permitData : originalData as unknown as JSON ,
1427+ } ;
1428+
1429+ return await this . create (
1430+ createDto ,
1431+ currentUser ,
1432+ original . company . companyId ,
1433+ ) ;
1434+ }
13901435}
You can’t perform that action at this time.
0 commit comments