diff --git a/backend/dops/src/modules/common/entities/base.entity.ts b/backend/dops/src/modules/common/entities/base.entity.ts index 035647529..2c61b0293 100644 --- a/backend/dops/src/modules/common/entities/base.entity.ts +++ b/backend/dops/src/modules/common/entities/base.entity.ts @@ -1,35 +1,40 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { - Column, - CreateDateColumn, - UpdateDateColumn, - VersionColumn, -} from 'typeorm'; +import { Column, CreateDateColumn, UpdateDateColumn } from 'typeorm'; export class Base { @AutoMap() - @ApiProperty({ description: 'Concurrency Control Number' }) - @VersionColumn({ - name: 'CONCURRENCY_CONTROL_NUMBER', + @ApiProperty({ description: 'Created User Name' }) + @Column({ + length: 30, + name: 'APP_CREATE_USERID', nullable: true, }) - concurrencyControlNumber: number; + createdUser: string; @AutoMap() - @ApiProperty({ description: 'Created User Name' }) + @ApiProperty({ description: 'Created User Directory' }) @Column({ length: 30, - name: 'DB_CREATE_USERID', + name: 'APP_CREATE_USER_DIRECTORY', nullable: true, }) - createdUser: string; + createdUserDirectory: string; + + @AutoMap() + @ApiProperty({ description: 'Created User GUID' }) + @Column({ + length: 32, + name: 'APP_CREATE_USER_GUID', + nullable: true, + }) + createdUserGuid: string; @AutoMap() @ApiProperty({ description: 'Resource Creation Date' }) @CreateDateColumn({ - default: () => 'NOW()', - name: 'DB_CREATE_TIMESTAMP', + default: () => 'GETUTCDATETIME()', + name: 'APP_CREATE_TIMESTAMP', nullable: true, }) createdDateTime: Date; @@ -38,16 +43,34 @@ export class Base { @ApiProperty({ description: 'Updated User Name' }) @Column({ length: 30, - name: 'DB_LAST_UPDATE_USERID', + name: 'APP_LAST_UPDATE_USERID', nullable: true, }) updatedUser: string; + @AutoMap() + @ApiProperty({ description: 'Updated User Directory' }) + @Column({ + length: 30, + name: 'APP_LAST_UPDATE_USER_DIRECTORY', + nullable: true, + }) + updatedUserDirectory: string; + + @AutoMap() + @ApiProperty({ description: 'Updated User GUID' }) + @Column({ + length: 32, + name: 'APP_LAST_UPDATE_USER_GUID', + nullable: true, + }) + updatedUserGuid: string; + @AutoMap() @ApiProperty({ description: 'Resource Update Date' }) @UpdateDateColumn({ - default: () => 'NOW()', - name: 'DB_LAST_UPDATE_TIMESTAMP', + default: () => 'GETUTCDATETIME()', + name: 'APP_LAST_UPDATE_TIMESTAMP', nullable: true, }) updatedDateTime: Date; diff --git a/backend/dops/src/modules/dgen/dgen.service.ts b/backend/dops/src/modules/dgen/dgen.service.ts index 161a5ea18..13cb25b19 100644 --- a/backend/dops/src/modules/dgen/dgen.service.ts +++ b/backend/dops/src/modules/dgen/dgen.service.ts @@ -27,6 +27,7 @@ import { CreateGeneratedReportDto } from './dto/request/create-generated-report. import puppeteer, { Browser } from 'puppeteer'; import { IFile } from '../../interface/file.interface'; import { ReportTemplate } from '../../enum/report-template.enum'; +import { getDirectory } from 'src/helper/auth.helper'; @Injectable() export class DgenService { @@ -119,6 +120,7 @@ export class DgenService { const dmsObject = await this.dmsService.create( currentUser, generatedDocument, + getDirectory(currentUser), companyId, ); res.setHeader('x-orbc-dms-id', dmsObject.documentId); @@ -259,7 +261,7 @@ export class DgenService { }); generatedDocument.size = generatedDocument.buffer.length; } catch (err) { - console.log("error on pup",err); + console.log('error on pup', err); throw new InternalServerErrorException(err); } finally { if (browser) { diff --git a/backend/dops/src/modules/dms/dms.controller.ts b/backend/dops/src/modules/dms/dms.controller.ts index a2c3b449e..f45e88531 100644 --- a/backend/dops/src/modules/dms/dms.controller.ts +++ b/backend/dops/src/modules/dms/dms.controller.ts @@ -36,6 +36,7 @@ import { IUserJWT } from '../../interface/user-jwt.interface'; import { IDP } from '../../enum/idp.enum'; import { Roles } from '../../decorator/roles.decorator'; import { Role } from '../../enum/roles.enum'; +import { getDirectory } from 'src/helper/auth.helper'; @ApiTags('DMS') @ApiBadRequestResponse({ @@ -91,6 +92,7 @@ export class DmsController { file: Express.Multer.File, ): Promise { const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); if (currentUser.identity_provider !== IDP.IDIR && !companyId) { throw new BadRequestException( 'Company Id is manadatory for all IDP but IDIR', @@ -100,7 +102,12 @@ export class DmsController { ? createFileDto.fileName : file.originalname; - return await this.dmsService.create(currentUser, file, companyId); + return await this.dmsService.create( + currentUser, + file, + directory, + companyId, + ); } @ApiCreatedResponse({ @@ -136,6 +143,7 @@ export class DmsController { file: Express.Multer.File, ): Promise { const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); if (currentUser.identity_provider !== IDP.IDIR && !companyId) { throw new BadRequestException( 'Company Id is manadatory for all IDP but IDIR', @@ -147,6 +155,7 @@ export class DmsController { return await this.dmsService.update( currentUser, + directory, documentId, file, companyId, diff --git a/backend/dops/src/modules/dms/dms.service.ts b/backend/dops/src/modules/dms/dms.service.ts index 8f12cebfd..eefc2293b 100644 --- a/backend/dops/src/modules/dms/dms.service.ts +++ b/backend/dops/src/modules/dms/dms.service.ts @@ -16,6 +16,7 @@ import { S3Service } from '../common/s3.service'; import { Response } from 'express'; import { v4 as uuidv4 } from 'uuid'; import { IDP } from '../../enum/idp.enum'; +import { Directory } from 'src/enum/directory.enum'; @Injectable() export class DmsService { @@ -31,6 +32,7 @@ export class DmsService { async create( currentUser: IUserJWT, file: Express.Multer.File | IFile, + directory: Directory, companyId?: number, ): Promise { // eslint-disable-next-line @typescript-eslint/no-unsafe-call @@ -48,6 +50,14 @@ export class DmsService { fileName: file.filename ? file.filename : file.originalname, dmsVersionId: dmsVersionId, companyId: companyId, + createdDateTime: new Date(), + createdUser: currentUser.userName, + createdUserDirectory: directory, + createdUserGuid: currentUser.userGUID, + updatedUser: currentUser.userName, + updatedDateTime: new Date(), + updatedUserGuid: currentUser.userGUID, + updatedUserDirectory: directory, }; return this.classMapper.mapAsync( @@ -59,6 +69,7 @@ export class DmsService { async update( currentUser: IUserJWT, + directory: Directory, documentId: string, file: Express.Multer.File, companyId?: number, @@ -86,6 +97,10 @@ export class DmsService { fileName: file.filename, dmsVersionId: dmsObject.dmsVersionId + 1, companyId: companyId, + updatedUser: currentUser.userName, + updatedDateTime: new Date(), + updatedUserGuid: currentUser.userGUID, + updatedUserDirectory: directory, }; return this.classMapper.mapAsync( diff --git a/backend/dops/src/modules/dms/dto/base.dto.ts b/backend/dops/src/modules/dms/dto/base.dto.ts index 1eeae419b..57f814ad7 100644 --- a/backend/dops/src/modules/dms/dto/base.dto.ts +++ b/backend/dops/src/modules/dms/dto/base.dto.ts @@ -2,10 +2,6 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; export class BaseDto { - @AutoMap() - @ApiProperty({ example: '1', description: 'Concurrency Control Number' }) - concurrencyControlNumber: number; - @AutoMap() @ApiProperty({ description: 'Created by', @@ -13,6 +9,17 @@ export class BaseDto { }) createdUser: string; + @AutoMap() + @ApiProperty({ description: 'Created User Directory', example: 'user1' }) + createdUserDirectory: string; + + @AutoMap() + @ApiProperty({ + description: 'Created User GUID', + example: '06267945F2EB4E31B585932F78B76269', + }) + createdUserGuid: string; + @AutoMap() @ApiProperty({ description: 'Created Date and Time', @@ -26,6 +33,20 @@ export class BaseDto { }) updatedUser: string; + @AutoMap() + @ApiProperty({ + description: 'Updated User Directory', + example: 'user1', + }) + updatedUserDirectory: string; + + @AutoMap() + @ApiProperty({ + description: 'Updated User GUID', + example: '06267945F2EB4E31B585932F78B76269', + }) + updatedUserGuid: string; + @AutoMap() @ApiProperty({ description: 'Updated Date and Time', diff --git a/backend/vehicles/src/common/helper/paginate.ts b/backend/vehicles/src/common/helper/paginate.ts index b0c81897a..aeb5b85ef 100644 --- a/backend/vehicles/src/common/helper/paginate.ts +++ b/backend/vehicles/src/common/helper/paginate.ts @@ -34,7 +34,7 @@ export async function paginate( } function resolveOptions( - options: IPaginationOptions, + options: IPaginationOptions, ): [number, number, PaginationTypeEnum, boolean, TypeORMCacheType] { const page = resolveNumericOption(options, 'page', DEFAULT_PAGE); const limit = resolveNumericOption(options, 'limit', DEFAULT_LIMIT); @@ -48,7 +48,7 @@ function resolveOptions( } function resolveNumericOption( - options: IPaginationOptions, + options: IPaginationOptions, key: 'page' | 'limit', defaultValue: number, ): number { diff --git a/backend/vehicles/src/common/interface/pagination.interface.ts b/backend/vehicles/src/common/interface/pagination.interface.ts index 28d4dca2b..2201108bb 100644 --- a/backend/vehicles/src/common/interface/pagination.interface.ts +++ b/backend/vehicles/src/common/interface/pagination.interface.ts @@ -46,7 +46,7 @@ export type TypeORMCacheType = | boolean | number | { - id: any; + id: unknown; milliseconds: number; }; diff --git a/backend/vehicles/src/modules/common/dto/base.dto.ts b/backend/vehicles/src/modules/common/dto/base.dto.ts index 1eeae419b..57f814ad7 100644 --- a/backend/vehicles/src/modules/common/dto/base.dto.ts +++ b/backend/vehicles/src/modules/common/dto/base.dto.ts @@ -2,10 +2,6 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; export class BaseDto { - @AutoMap() - @ApiProperty({ example: '1', description: 'Concurrency Control Number' }) - concurrencyControlNumber: number; - @AutoMap() @ApiProperty({ description: 'Created by', @@ -13,6 +9,17 @@ export class BaseDto { }) createdUser: string; + @AutoMap() + @ApiProperty({ description: 'Created User Directory', example: 'user1' }) + createdUserDirectory: string; + + @AutoMap() + @ApiProperty({ + description: 'Created User GUID', + example: '06267945F2EB4E31B585932F78B76269', + }) + createdUserGuid: string; + @AutoMap() @ApiProperty({ description: 'Created Date and Time', @@ -26,6 +33,20 @@ export class BaseDto { }) updatedUser: string; + @AutoMap() + @ApiProperty({ + description: 'Updated User Directory', + example: 'user1', + }) + updatedUserDirectory: string; + + @AutoMap() + @ApiProperty({ + description: 'Updated User GUID', + example: '06267945F2EB4E31B585932F78B76269', + }) + updatedUserGuid: string; + @AutoMap() @ApiProperty({ description: 'Updated Date and Time', diff --git a/backend/vehicles/src/modules/common/dto/country.dto.ts b/backend/vehicles/src/modules/common/dto/country.dto.ts index 35902980d..b1645dcac 100644 --- a/backend/vehicles/src/modules/common/dto/country.dto.ts +++ b/backend/vehicles/src/modules/common/dto/country.dto.ts @@ -1,8 +1,7 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { BaseDto } from './base.dto'; -export class CountryDto extends BaseDto { +export class CountryDto { @AutoMap() @ApiProperty({ example: 'CA', diff --git a/backend/vehicles/src/modules/common/dto/province.dto.ts b/backend/vehicles/src/modules/common/dto/province.dto.ts index bcde3c7a2..50ae2422a 100644 --- a/backend/vehicles/src/modules/common/dto/province.dto.ts +++ b/backend/vehicles/src/modules/common/dto/province.dto.ts @@ -1,9 +1,8 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { BaseDto } from './base.dto'; import { CountryDto } from './country.dto'; -export class ProvinceDto extends BaseDto { +export class ProvinceDto { @AutoMap() @ApiProperty({ example: 'BC', description: 'Province Code' }) provinceCode: string; diff --git a/backend/vehicles/src/modules/common/entities/base.entity.ts b/backend/vehicles/src/modules/common/entities/base.entity.ts index 89bc4e18b..2c61b0293 100644 --- a/backend/vehicles/src/modules/common/entities/base.entity.ts +++ b/backend/vehicles/src/modules/common/entities/base.entity.ts @@ -1,35 +1,40 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { - Column, - CreateDateColumn, - UpdateDateColumn, - VersionColumn, -} from 'typeorm'; +import { Column, CreateDateColumn, UpdateDateColumn } from 'typeorm'; export class Base { @AutoMap() - @ApiProperty({ description: 'Concurrency Control Number' }) - @VersionColumn({ - name: 'CONCURRENCY_CONTROL_NUMBER', + @ApiProperty({ description: 'Created User Name' }) + @Column({ + length: 30, + name: 'APP_CREATE_USERID', nullable: true, }) - concurrencyControlNumber: number; + createdUser: string; @AutoMap() - @ApiProperty({ description: 'Created User Name' }) + @ApiProperty({ description: 'Created User Directory' }) @Column({ length: 30, - name: 'DB_CREATE_USERID', + name: 'APP_CREATE_USER_DIRECTORY', nullable: true, }) - createdUser: string; + createdUserDirectory: string; + + @AutoMap() + @ApiProperty({ description: 'Created User GUID' }) + @Column({ + length: 32, + name: 'APP_CREATE_USER_GUID', + nullable: true, + }) + createdUserGuid: string; @AutoMap() @ApiProperty({ description: 'Resource Creation Date' }) @CreateDateColumn({ default: () => 'GETUTCDATETIME()', - name: 'DB_CREATE_TIMESTAMP', + name: 'APP_CREATE_TIMESTAMP', nullable: true, }) createdDateTime: Date; @@ -38,16 +43,34 @@ export class Base { @ApiProperty({ description: 'Updated User Name' }) @Column({ length: 30, - name: 'DB_LAST_UPDATE_USERID', + name: 'APP_LAST_UPDATE_USERID', nullable: true, }) updatedUser: string; + @AutoMap() + @ApiProperty({ description: 'Updated User Directory' }) + @Column({ + length: 30, + name: 'APP_LAST_UPDATE_USER_DIRECTORY', + nullable: true, + }) + updatedUserDirectory: string; + + @AutoMap() + @ApiProperty({ description: 'Updated User GUID' }) + @Column({ + length: 32, + name: 'APP_LAST_UPDATE_USER_GUID', + nullable: true, + }) + updatedUserGuid: string; + @AutoMap() @ApiProperty({ description: 'Resource Update Date' }) @UpdateDateColumn({ default: () => 'GETUTCDATETIME()', - name: 'DB_LAST_UPDATE_TIMESTAMP', + name: 'APP_LAST_UPDATE_TIMESTAMP', nullable: true, }) updatedDateTime: Date; diff --git a/backend/vehicles/src/modules/common/entities/country.entity.ts b/backend/vehicles/src/modules/common/entities/country.entity.ts index 670ee848e..8f2996a5d 100644 --- a/backend/vehicles/src/modules/common/entities/country.entity.ts +++ b/backend/vehicles/src/modules/common/entities/country.entity.ts @@ -1,11 +1,10 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; import { Entity, Column, OneToMany, PrimaryColumn } from 'typeorm'; -import { Base } from './base.entity'; import { Province } from './province.entity'; @Entity({ name: 'ORBC_VT_COUNTRY' }) -export class Country extends Base { +export class Country { @AutoMap() @ApiProperty({ example: 'CA', description: 'Country Code' }) @PrimaryColumn({ length: 2, name: 'COUNTRY_CODE', nullable: false }) diff --git a/backend/vehicles/src/modules/common/entities/province.entity.ts b/backend/vehicles/src/modules/common/entities/province.entity.ts index 58725d727..b65bc9c8c 100644 --- a/backend/vehicles/src/modules/common/entities/province.entity.ts +++ b/backend/vehicles/src/modules/common/entities/province.entity.ts @@ -7,7 +7,6 @@ import { OneToMany, PrimaryColumn, } from 'typeorm'; -import { Base } from './base.entity'; import { Country } from './country.entity'; import { AutoMap } from '@automapper/classes'; import { Contact } from './contact.entity'; @@ -16,7 +15,7 @@ import { PowerUnit } from '../../vehicles/power-units/entities/power-unit.entity import { Trailer } from '../../vehicles/trailers/entities/trailer.entity'; @Entity({ name: 'ORBC_VT_PROVINCE' }) -export class Province extends Base { +export class Province { @AutoMap() @ApiProperty({ example: 'CA-BC', description: 'Province ID' }) @PrimaryColumn({ length: 5, name: 'PROVINCE_ID', nullable: false }) diff --git a/backend/vehicles/src/modules/company-user-management/company/company.controller.ts b/backend/vehicles/src/modules/company-user-management/company/company.controller.ts index c69e40d66..460496c24 100644 --- a/backend/vehicles/src/modules/company-user-management/company/company.controller.ts +++ b/backend/vehicles/src/modules/company-user-management/company/company.controller.ts @@ -170,13 +170,16 @@ export class CompanyController { @Roles(Role.WRITE_ORG) @Put(':companyId') async update( + @Req() request: Request, @Param('companyId') companyId: number, @Body() updateCompanyDto: UpdateCompanyDto, ): Promise { + const currentUser = request.user as IUserJWT; const retCompany = await this.companyService.update( companyId, updateCompanyDto, Directory.BBCEID, + currentUser, ); if (!retCompany) { throw new DataNotFoundException(); diff --git a/backend/vehicles/src/modules/company-user-management/company/company.service.ts b/backend/vehicles/src/modules/company-user-management/company/company.service.ts index 05a4a53d6..54d2eecdb 100644 --- a/backend/vehicles/src/modules/company-user-management/company/company.service.ts +++ b/backend/vehicles/src/modules/company-user-management/company/company.service.ts @@ -78,6 +78,9 @@ export class CompanyService { directory: directory, companyGUID: currentUser.bceid_business_guid, accountSource: currentUser.accountSource, + userName: currentUser.userName, + userGUID: currentUser.userGUID, + timestamp: new Date(), }), }, ); @@ -98,6 +101,7 @@ export class CompanyService { userName: currentUser.userName, directory: directory, userGUID: currentUser.userGUID, + timestamp: new Date(), }), }, ); @@ -303,6 +307,7 @@ export class CompanyService { companyId: number, updateCompanyDto: UpdateCompanyDto, directory: Directory, + currentUser: IUserJWT, ): Promise { const company = await this.companyRepository.findOne({ where: { companyId: companyId }, @@ -331,6 +336,9 @@ export class CompanyService { directory: directory, mailingAddressId: mailingAddressId, contactId: contactId, + userName: currentUser.userName, + userGUID: currentUser.userGUID, + timestamp: new Date(), }), }, ); diff --git a/backend/vehicles/src/modules/company-user-management/company/profiles/company.profile.ts b/backend/vehicles/src/modules/company-user-management/company/profiles/company.profile.ts index b382fe089..0da2898d6 100644 --- a/backend/vehicles/src/modules/company-user-management/company/profiles/company.profile.ts +++ b/backend/vehicles/src/modules/company-user-management/company/profiles/company.profile.ts @@ -41,6 +41,57 @@ export class CompanyProfile extends AutomapperProfile { mapper, CreateCompanyDto, Company, + forMember( + (d) => d.createdUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.createdUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.createdUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.createdDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), + + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), forMember( (d) => d.companyGUID, mapWithArguments((source, { companyGUID }) => { @@ -89,6 +140,31 @@ export class CompanyProfile extends AutomapperProfile { mapper, UpdateCompanyDto, Company, + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), forMember( (d) => d.companyId, mapWithArguments((source, { companyId }) => { diff --git a/backend/vehicles/src/modules/company-user-management/pending-idir-users/pending-idir-users.controller.ts b/backend/vehicles/src/modules/company-user-management/pending-idir-users/pending-idir-users.controller.ts index 4200cfc63..40e7544d7 100644 --- a/backend/vehicles/src/modules/company-user-management/pending-idir-users/pending-idir-users.controller.ts +++ b/backend/vehicles/src/modules/company-user-management/pending-idir-users/pending-idir-users.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Post, Body, Get } from '@nestjs/common'; +import { Controller, Post, Body, Get, Req } from '@nestjs/common'; import { ApiBadRequestResponse, @@ -12,6 +12,9 @@ import { ExceptionDto } from '../../../common/exception/exception.dto'; import { CreatePendingIdirUserDto } from './dto/request/create-pending-idir-user.dto'; import { PendingIdirUsersService } from './pending-idir-users.service'; import { ReadPendingIdirUserDto } from './dto/response/read-pending-idir-user.dto'; +import { getDirectory } from 'src/common/helper/auth.helper'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; +import { Request } from 'express'; @ApiTags('User Management - Pending IDIR User') @ApiBadRequestResponse({ @@ -46,10 +49,15 @@ export class PendingIdirUsersController { */ @Post() async create( + @Req() request: Request, @Body() createPendingIdirUserDto: CreatePendingIdirUserDto, ): Promise { + const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); const pendingIdirUser = await this.pendingIdirUserService.create( createPendingIdirUserDto, + directory, + currentUser, ); return pendingIdirUser; } diff --git a/backend/vehicles/src/modules/company-user-management/pending-idir-users/pending-idir-users.service.ts b/backend/vehicles/src/modules/company-user-management/pending-idir-users/pending-idir-users.service.ts index 724666fb3..c6a47e546 100644 --- a/backend/vehicles/src/modules/company-user-management/pending-idir-users/pending-idir-users.service.ts +++ b/backend/vehicles/src/modules/company-user-management/pending-idir-users/pending-idir-users.service.ts @@ -6,6 +6,8 @@ import { Repository } from 'typeorm'; import { PendingIdirUser } from './entities/pending-idir-user.entity'; import { CreatePendingIdirUserDto } from './dto/request/create-pending-idir-user.dto'; import { ReadPendingIdirUserDto } from './dto/response/read-pending-idir-user.dto'; +import { Directory } from 'src/common/enum/directory.enum'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; @Injectable() export class PendingIdirUsersService { @@ -25,11 +27,21 @@ export class PendingIdirUsersService { */ async create( createPendingIdirUserDto: CreatePendingIdirUserDto, + directory: Directory, + currentUser: IUserJWT, ): Promise { const newPendingIdirUserDto = this.classMapper.map( createPendingIdirUserDto, CreatePendingIdirUserDto, PendingIdirUser, + { + extraArgs: () => ({ + userName: currentUser.userName, + directory: directory, + userGUID: currentUser.userGUID, + timestamp: new Date(), + }), + }, ); const idirUser = await this.pendingIdirUserRepository.save( newPendingIdirUserDto, diff --git a/backend/vehicles/src/modules/company-user-management/pending-idir-users/profiles/pending-idir-user.profile.ts b/backend/vehicles/src/modules/company-user-management/pending-idir-users/profiles/pending-idir-user.profile.ts index b291c08de..2fb7711a0 100644 --- a/backend/vehicles/src/modules/company-user-management/pending-idir-users/profiles/pending-idir-user.profile.ts +++ b/backend/vehicles/src/modules/company-user-management/pending-idir-users/profiles/pending-idir-user.profile.ts @@ -1,5 +1,10 @@ import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; -import { createMap, Mapper } from '@automapper/core'; +import { + createMap, + forMember, + Mapper, + mapWithArguments, +} from '@automapper/core'; import { Injectable } from '@nestjs/common'; import { ReadPendingIdirUserDto } from '../dto/response/read-pending-idir-user.dto'; import { CreatePendingIdirUserDto } from '../dto/request/create-pending-idir-user.dto'; @@ -19,7 +24,62 @@ export class PendingIdirUsersProfile extends AutomapperProfile { * mappings for the userName properties using forMember * and mapWithArguments. */ - createMap(mapper, CreatePendingIdirUserDto, PendingIdirUser); + createMap( + mapper, + CreatePendingIdirUserDto, + PendingIdirUser, + forMember( + (d) => d.createdUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.createdUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.createdUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.createdDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), + + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), + ); /** * Mapping from CreatePendingIdirUserDto to PendingIdirUser entity, with custom diff --git a/backend/vehicles/src/modules/company-user-management/pending-users/pending-users.controller.ts b/backend/vehicles/src/modules/company-user-management/pending-users/pending-users.controller.ts index 551c7e7d5..ff0c56024 100644 --- a/backend/vehicles/src/modules/company-user-management/pending-users/pending-users.controller.ts +++ b/backend/vehicles/src/modules/company-user-management/pending-users/pending-users.controller.ts @@ -6,6 +6,7 @@ import { Param, Put, Delete, + Req, } from '@nestjs/common'; import { @@ -24,6 +25,9 @@ import { CreatePendingUserDto } from './dto/request/create-pending-user.dto'; import { UpdatePendingUserDto } from './dto/request/update-pending-user.dto'; import { ReadPendingUserDto } from './dto/response/read-pending-user.dto'; import { PendingUsersService } from './pending-users.service'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; +import { Request } from 'express'; +import { getDirectory } from 'src/common/helper/auth.helper'; @ApiTags('Company and User Management - Pending User') @ApiBadRequestResponse({ @@ -66,10 +70,18 @@ export class PendingUsersController { }) @Post() async create( + @Req() request: Request, @Param('companyId') companyId: number, @Body() createUserDto: CreatePendingUserDto, ) { - return await this.pendingUserService.create(companyId, createUserDto); + const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); + return await this.pendingUserService.create( + companyId, + createUserDto, + directory, + currentUser, + ); } /** @@ -148,14 +160,19 @@ export class PendingUsersController { }) @Put(':userName') async update( + @Req() request: Request, @Param('companyId') companyId: number, @Param('userName') userName: string, @Body() updatePendingUserDto: UpdatePendingUserDto, ): Promise { + const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); const pendingUser = await this.pendingUserService.update( companyId, userName, updatePendingUserDto, + directory, + currentUser, ); if (!pendingUser) { throw new DataNotFoundException(); diff --git a/backend/vehicles/src/modules/company-user-management/pending-users/pending-users.service.ts b/backend/vehicles/src/modules/company-user-management/pending-users/pending-users.service.ts index ecd25a788..25eace48d 100644 --- a/backend/vehicles/src/modules/company-user-management/pending-users/pending-users.service.ts +++ b/backend/vehicles/src/modules/company-user-management/pending-users/pending-users.service.ts @@ -7,6 +7,8 @@ import { CreatePendingUserDto } from './dto/request/create-pending-user.dto'; import { UpdatePendingUserDto } from './dto/request/update-pending-user.dto'; import { ReadPendingUserDto } from './dto/response/read-pending-user.dto'; import { PendingUser } from './entities/pending-user.entity'; +import { Directory } from 'src/common/enum/directory.enum'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; @Injectable() export class PendingUsersService { @@ -29,13 +31,21 @@ export class PendingUsersService { async create( companyId: number, createPendingUserDto: CreatePendingUserDto, + directory: Directory, + currentUser: IUserJWT, ): Promise { const newPendingUserDto = this.classMapper.map( createPendingUserDto, CreatePendingUserDto, PendingUser, { - extraArgs: () => ({ companyId: companyId }), + extraArgs: () => ({ + companyId: companyId, + userName: currentUser.userName, + directory: directory, + userGUID: currentUser.userGUID, + timestamp: new Date(), + }), }, ); @@ -64,13 +74,21 @@ export class PendingUsersService { companyId: number, userName: string, updatePendingUserDto: UpdatePendingUserDto, + directory: Directory, + currentUser: IUserJWT, ): Promise { const updatePendingUser = this.classMapper.map( updatePendingUserDto, UpdatePendingUserDto, PendingUser, { - extraArgs: () => ({ companyId: companyId, userName: userName }), + extraArgs: () => ({ + companyId: companyId, + userName: currentUser.userName, + directory: directory, + userGUID: currentUser.userGUID, + timestamp: new Date(), + }), }, ); diff --git a/backend/vehicles/src/modules/company-user-management/pending-users/profiles/pending-user.profile.ts b/backend/vehicles/src/modules/company-user-management/pending-users/profiles/pending-user.profile.ts index 55c463455..1ef281850 100644 --- a/backend/vehicles/src/modules/company-user-management/pending-users/profiles/pending-user.profile.ts +++ b/backend/vehicles/src/modules/company-user-management/pending-users/profiles/pending-user.profile.ts @@ -35,6 +35,57 @@ export class PendingUsersProfile extends AutomapperProfile { return companyId; }), ), + forMember( + (d) => d.createdUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.createdUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.createdUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.createdDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), + + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), ); /** @@ -58,6 +109,30 @@ export class PendingUsersProfile extends AutomapperProfile { return userName; }), ), + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), ); /** diff --git a/backend/vehicles/src/modules/company-user-management/users/company-users.controller.ts b/backend/vehicles/src/modules/company-user-management/users/company-users.controller.ts index dece09000..a1bf5db47 100644 --- a/backend/vehicles/src/modules/company-user-management/users/company-users.controller.ts +++ b/backend/vehicles/src/modules/company-user-management/users/company-users.controller.ts @@ -134,10 +134,12 @@ export class CompanyUsersController { @Body() updateUserDto: UpdateUserDto, ): Promise { const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); const user = await this.userService.update( userGUID, updateUserDto, companyId, + directory, currentUser, ); if (!user) { @@ -169,9 +171,13 @@ export class CompanyUsersController { @Param('userGUID') userGUID: string, @Body() updateUserStatusDto: UpdateUserStatusDto, ): Promise { + const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); const updateResult = await this.userService.updateStatus( userGUID, updateUserStatusDto.statusCode, + directory, + currentUser, ); if (updateResult.affected === 0) { throw new DataNotFoundException(); diff --git a/backend/vehicles/src/modules/company-user-management/users/profiles/user.profile.ts b/backend/vehicles/src/modules/company-user-management/users/profiles/user.profile.ts index e760ed307..6ab24ae6b 100644 --- a/backend/vehicles/src/modules/company-user-management/users/profiles/user.profile.ts +++ b/backend/vehicles/src/modules/company-user-management/users/profiles/user.profile.ts @@ -59,6 +59,57 @@ export class UsersProfile extends AutomapperProfile { return directory; }), ), + forMember( + (d) => d.createdUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.createdUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.createdUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.createdDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), + + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), forMember( (d) => d.userContact, mapFrom((s) => { @@ -80,12 +131,84 @@ export class UsersProfile extends AutomapperProfile { return userGUID; }), ), + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), forMember( (d) => d.userContact, mapFrom((s) => { return this.mapper.map(s, CreateContactDto, Contact); }), ), + forMember( + (d) => d.userContact.createdUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.userContact.createdDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), + forMember( + (d) => d.userContact.createdUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + forMember( + (d) => d.userContact.createdUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.userContact.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.userContact.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), + forMember( + (d) => d.userContact.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + forMember( + (d) => d.userContact.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), forMember((d) => d.userAuthGroup, ignore()), ); diff --git a/backend/vehicles/src/modules/company-user-management/users/users.service.ts b/backend/vehicles/src/modules/company-user-management/users/users.service.ts index 0df6c84ba..dda332940 100644 --- a/backend/vehicles/src/modules/company-user-management/users/users.service.ts +++ b/backend/vehicles/src/modules/company-user-management/users/users.service.ts @@ -80,6 +80,7 @@ export class UsersService { userName: currentUser.userName, directory: directory, userGUID: currentUser.userGUID, + timestamp: new Date(), }), }); @@ -125,6 +126,7 @@ export class UsersService { userGUID: string, updateUserDto: UpdateUserDto, companyId: number, + directory: Directory, // eslint-disable-next-line @typescript-eslint/no-unused-vars currentUser?: IUserJWT, ): Promise { @@ -136,7 +138,10 @@ export class UsersService { const user = this.classMapper.map(updateUserDto, UpdateUserDto, User, { extraArgs: () => ({ - userGUID: userGUID, + userName: currentUser.userName, + directory: directory, + userGUID: currentUser.userGUID, + timestamp: new Date(), }), }); user.userContact.contactId = userDetails[0]?.userContact?.contactId; @@ -204,10 +209,16 @@ export class UsersService { async updateStatus( userGUID: string, statusCode: UserStatus, + directory: Directory, + currentUser?: IUserJWT, ): Promise { const user = new User(); user.userGUID = userGUID; user.statusCode = statusCode; + user.updatedUserGuid = currentUser.userGUID; + user.updatedDateTime = new Date(); + user.updatedUser = currentUser.userName; + user.updatedUserDirectory = directory; return await this.userRepository.update({ userGUID }, user); } diff --git a/backend/vehicles/src/modules/payment/payment.controller.ts b/backend/vehicles/src/modules/payment/payment.controller.ts index e46d1459d..ae349fe4c 100644 --- a/backend/vehicles/src/modules/payment/payment.controller.ts +++ b/backend/vehicles/src/modules/payment/payment.controller.ts @@ -100,4 +100,4 @@ export class PaymentController { transaction.transactionId, ); } -} +} \ No newline at end of file diff --git a/backend/vehicles/src/modules/payment/payment.service.ts b/backend/vehicles/src/modules/payment/payment.service.ts index c0c77429f..d14c27db5 100644 --- a/backend/vehicles/src/modules/payment/payment.service.ts +++ b/backend/vehicles/src/modules/payment/payment.service.ts @@ -326,4 +326,4 @@ export class PaymentService { ReadPermitTransactionDto, ); } -} +} \ No newline at end of file diff --git a/backend/vehicles/src/modules/payment/profile/transaction.profile.ts b/backend/vehicles/src/modules/payment/profile/transaction.profile.ts index 0c9880e38..80e639ba7 100644 --- a/backend/vehicles/src/modules/payment/profile/transaction.profile.ts +++ b/backend/vehicles/src/modules/payment/profile/transaction.profile.ts @@ -19,4 +19,4 @@ export class TransactionProfile extends AutomapperProfile { createMap(mapper, Transaction, ReadPermitTransactionDto); }; } -} +} \ No newline at end of file diff --git a/backend/vehicles/src/modules/permit/application.controller.ts b/backend/vehicles/src/modules/permit/application.controller.ts index c9ccfabd5..ae3d27fe2 100644 --- a/backend/vehicles/src/modules/permit/application.controller.ts +++ b/backend/vehicles/src/modules/permit/application.controller.ts @@ -176,4 +176,4 @@ export class ApplicationController { } return result; } -} +} \ No newline at end of file diff --git a/backend/vehicles/src/modules/permit/application.service.ts b/backend/vehicles/src/modules/permit/application.service.ts index 5db79bf02..416302e5c 100644 --- a/backend/vehicles/src/modules/permit/application.service.ts +++ b/backend/vehicles/src/modules/permit/application.service.ts @@ -740,4 +740,4 @@ export class ApplicationService { .getCount(); return count; } -} +} \ No newline at end of file diff --git a/backend/vehicles/src/modules/permit/entities/permit-application-origin.entity.ts b/backend/vehicles/src/modules/permit/entities/permit-application-origin.entity.ts index a6c18fdac..95a5ed728 100644 --- a/backend/vehicles/src/modules/permit/entities/permit-application-origin.entity.ts +++ b/backend/vehicles/src/modules/permit/entities/permit-application-origin.entity.ts @@ -1,11 +1,10 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { Base } from 'src/modules/common/entities/base.entity'; import { Column, Entity, PrimaryColumn } from 'typeorm'; import { PermitApplicationOrigin as PermitApplicationOriginEnum } from 'src/common/enum/permit-application-origin.enum'; @Entity({ name: 'permit.ORBC_VT_PERMIT_APPLICATION_ORIGIN' }) -export class PermitApplicationOrigin extends Base { +export class PermitApplicationOrigin { @AutoMap() @ApiProperty({ example: 'ONLINE', diff --git a/backend/vehicles/src/modules/permit/entities/permit-approval-source.entity.ts b/backend/vehicles/src/modules/permit/entities/permit-approval-source.entity.ts index cb3cb4e2d..976443783 100644 --- a/backend/vehicles/src/modules/permit/entities/permit-approval-source.entity.ts +++ b/backend/vehicles/src/modules/permit/entities/permit-approval-source.entity.ts @@ -1,11 +1,10 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; -import { Base } from 'src/modules/common/entities/base.entity'; import { Column, Entity, PrimaryColumn } from 'typeorm'; import { PermitApprovalSource as PermitApprovalSourceEnum } from 'src/common/enum/permit-approval-source.enum'; @Entity({ name: 'permit.ORBC_VT_PERMIT_APPROVAL_SOURCE' }) -export class PermitApprovalSource extends Base { +export class PermitApprovalSource { @AutoMap() @ApiProperty({ example: 'ONLINE', diff --git a/backend/vehicles/src/modules/permit/permit.controller.ts b/backend/vehicles/src/modules/permit/permit.controller.ts index 8f0d1d111..61e944613 100644 --- a/backend/vehicles/src/modules/permit/permit.controller.ts +++ b/backend/vehicles/src/modules/permit/permit.controller.ts @@ -254,4 +254,4 @@ export class PermitController { ); return permit; } -} +} \ No newline at end of file diff --git a/backend/vehicles/src/modules/permit/permit.service.ts b/backend/vehicles/src/modules/permit/permit.service.ts index 3c715245b..1956cc0d8 100644 --- a/backend/vehicles/src/modules/permit/permit.service.ts +++ b/backend/vehicles/src/modules/permit/permit.service.ts @@ -529,4 +529,4 @@ export class PermitService { }; return resultDto; } -} +} \ No newline at end of file diff --git a/backend/vehicles/src/modules/permit/profile/application.profile.ts b/backend/vehicles/src/modules/permit/profile/application.profile.ts index aff267b4a..a4dfca79c 100644 --- a/backend/vehicles/src/modules/permit/profile/application.profile.ts +++ b/backend/vehicles/src/modules/permit/profile/application.profile.ts @@ -77,4 +77,4 @@ export class ApplicationProfile extends AutomapperProfile { ); }; } -} +} \ No newline at end of file diff --git a/backend/vehicles/src/modules/permit/profile/permit.profile.ts b/backend/vehicles/src/modules/permit/profile/permit.profile.ts index 6caf75d1e..eb664cf4e 100644 --- a/backend/vehicles/src/modules/permit/profile/permit.profile.ts +++ b/backend/vehicles/src/modules/permit/profile/permit.profile.ts @@ -89,4 +89,4 @@ export class PermitProfile extends AutomapperProfile { ); }; } -} +} \ No newline at end of file diff --git a/backend/vehicles/src/modules/vehicles/power-unit-types/entities/power-unit-type.entity.ts b/backend/vehicles/src/modules/vehicles/power-unit-types/entities/power-unit-type.entity.ts index a2931f7ef..0ccd7cc57 100644 --- a/backend/vehicles/src/modules/vehicles/power-unit-types/entities/power-unit-type.entity.ts +++ b/backend/vehicles/src/modules/vehicles/power-unit-types/entities/power-unit-type.entity.ts @@ -1,11 +1,10 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; import { Entity, Column, OneToMany, PrimaryColumn } from 'typeorm'; -import { Base } from '../../../common/entities/base.entity'; import { PowerUnit } from '../../power-units/entities/power-unit.entity'; @Entity({ name: 'ORBC_VT_POWER_UNIT_TYPE' }) -export class PowerUnitType extends Base { +export class PowerUnitType { @AutoMap() @ApiProperty({ example: 'CONCRET', diff --git a/backend/vehicles/src/modules/vehicles/power-units/power-units.controller.ts b/backend/vehicles/src/modules/vehicles/power-units/power-units.controller.ts index 23e9b8684..166db0d93 100644 --- a/backend/vehicles/src/modules/vehicles/power-units/power-units.controller.ts +++ b/backend/vehicles/src/modules/vehicles/power-units/power-units.controller.ts @@ -32,6 +32,8 @@ import { Roles } from '../../../common/decorator/roles.decorator'; import { Role } from '../../../common/enum/roles.enum'; import { DeleteDto } from 'src/modules/common/dto/response/delete.dto'; import { DeletePowerUnitDto } from './dto/request/delete-power-units.dto'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; +import { getDirectory } from 'src/common/helper/auth.helper'; @ApiTags('Vehicles - Power Units') @ApiBadRequestResponse({ @@ -66,8 +68,14 @@ export class PowerUnitsController { @Param('companyId') companyId: number, @Body() createPowerUnitDto: CreatePowerUnitDto, ) { - //const currentUser = request.user as IUserJWT; - return await this.powerUnitsService.create(companyId, createPowerUnitDto); + const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); + return await this.powerUnitsService.create( + companyId, + createPowerUnitDto, + currentUser, + directory, + ); } @ApiOkResponse({ @@ -115,12 +123,15 @@ export class PowerUnitsController { @Param('powerUnitId') powerUnitId: string, @Body() updatePowerUnitDto: UpdatePowerUnitDto, ): Promise { - //const currentUser = request.user as IUserJWT; + const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); await this.checkVehicleCompanyContext(companyId, powerUnitId); const powerUnit = await this.powerUnitsService.update( companyId, powerUnitId, updatePowerUnitDto, + currentUser, + directory, ); if (!powerUnit) { throw new DataNotFoundException(); diff --git a/backend/vehicles/src/modules/vehicles/power-units/power-units.service.ts b/backend/vehicles/src/modules/vehicles/power-units/power-units.service.ts index 01cef2d2b..f6e9294e8 100644 --- a/backend/vehicles/src/modules/vehicles/power-units/power-units.service.ts +++ b/backend/vehicles/src/modules/vehicles/power-units/power-units.service.ts @@ -8,6 +8,8 @@ import { InjectMapper } from '@automapper/nestjs'; import { Mapper } from '@automapper/core'; import { ReadPowerUnitDto } from './dto/response/read-power-unit.dto'; import { DeleteDto } from 'src/modules/common/dto/response/delete.dto'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; +import { Directory } from 'src/common/enum/directory.enum'; @Injectable() export class PowerUnitsService { @@ -20,13 +22,21 @@ export class PowerUnitsService { async create( companyId: number, powerUnit: CreatePowerUnitDto, + currentUser: IUserJWT, + directory: Directory, ): Promise { const newPowerUnit = this.classMapper.map( powerUnit, CreatePowerUnitDto, PowerUnit, { - extraArgs: () => ({ companyId: companyId }), + extraArgs: () => ({ + companyId: companyId, + userName: currentUser.userName, + directory: directory, + userGUID: currentUser.userGUID, + timestamp: new Date(), + }), }, ); return this.classMapper.mapAsync( @@ -74,11 +84,21 @@ export class PowerUnitsService { companyId: number, powerUnitId: string, updatePowerUnitDto: UpdatePowerUnitDto, + currentUser: IUserJWT, + directory: Directory, ): Promise { const newPowerUnit = this.classMapper.map( updatePowerUnitDto, UpdatePowerUnitDto, PowerUnit, + { + extraArgs: () => ({ + userName: currentUser.userName, + directory: directory, + userGUID: currentUser.userGUID, + timestamp: new Date(), + }), + }, ); await this.powerUnitRepository.update( { powerUnitId: powerUnitId, companyId: companyId }, diff --git a/backend/vehicles/src/modules/vehicles/power-units/profiles/power-unit.profile.ts b/backend/vehicles/src/modules/vehicles/power-units/profiles/power-unit.profile.ts index 2a466a869..c563795d9 100644 --- a/backend/vehicles/src/modules/vehicles/power-units/profiles/power-unit.profile.ts +++ b/backend/vehicles/src/modules/vehicles/power-units/profiles/power-unit.profile.ts @@ -46,6 +46,57 @@ export class PowerUnitsProfile extends AutomapperProfile { mapper, CreatePowerUnitDto, PowerUnit, + forMember( + (d) => d.createdUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.createdUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.createdUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.createdDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), + + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), forMember( (d) => d.province.provinceId, mapFrom((s) => getProvinceId(s.countryCode, s.provinceCode)), @@ -65,6 +116,31 @@ export class PowerUnitsProfile extends AutomapperProfile { mapper, UpdatePowerUnitDto, PowerUnit, + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), forMember( (d) => d.province.provinceId, mapFrom((s) => getProvinceId(s.countryCode, s.provinceCode)), diff --git a/backend/vehicles/src/modules/vehicles/trailer-types/entities/trailer-type.entity.ts b/backend/vehicles/src/modules/vehicles/trailer-types/entities/trailer-type.entity.ts index 5c00c604a..523d72971 100644 --- a/backend/vehicles/src/modules/vehicles/trailer-types/entities/trailer-type.entity.ts +++ b/backend/vehicles/src/modules/vehicles/trailer-types/entities/trailer-type.entity.ts @@ -1,12 +1,10 @@ import { AutoMap } from '@automapper/classes'; import { ApiProperty } from '@nestjs/swagger'; import { Entity, Column, OneToMany, PrimaryColumn } from 'typeorm'; -import { Base } from '../../../common/entities/base.entity'; - import { Trailer } from '../../trailers/entities/trailer.entity'; @Entity({ name: 'ORBC_VT_TRAILER_TYPE' }) -export class TrailerType extends Base { +export class TrailerType { @AutoMap() @ApiProperty({ example: 'BOOSTER', diff --git a/backend/vehicles/src/modules/vehicles/trailers/profiles/trailer.profile.ts b/backend/vehicles/src/modules/vehicles/trailers/profiles/trailer.profile.ts index e27ab72fe..e374e6f27 100644 --- a/backend/vehicles/src/modules/vehicles/trailers/profiles/trailer.profile.ts +++ b/backend/vehicles/src/modules/vehicles/trailers/profiles/trailer.profile.ts @@ -46,6 +46,57 @@ export class TrailersProfile extends AutomapperProfile { mapper, CreateTrailerDto, Trailer, + forMember( + (d) => d.createdUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.createdUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.createdUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.createdDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), + + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), forMember( (d) => d.province.provinceId, mapFrom((s) => getProvinceId(s.countryCode, s.provinceCode)), @@ -65,6 +116,31 @@ export class TrailersProfile extends AutomapperProfile { mapper, UpdateTrailerDto, Trailer, + forMember( + (d) => d.updatedUserGuid, + mapWithArguments((source, { userGUID }) => { + return userGUID; + }), + ), + forMember( + (d) => d.updatedUser, + mapWithArguments((source, { userName }) => { + return userName; + }), + ), + forMember( + (d) => d.updatedUserDirectory, + mapWithArguments((source, { directory }) => { + return directory; + }), + ), + + forMember( + (d) => d.updatedDateTime, + mapWithArguments((source, { timestamp }) => { + return timestamp; + }), + ), forMember( (d) => d.province.provinceId, mapFrom((s) => getProvinceId(s.countryCode, s.provinceCode)), diff --git a/backend/vehicles/src/modules/vehicles/trailers/trailers.controller.ts b/backend/vehicles/src/modules/vehicles/trailers/trailers.controller.ts index 4067faa00..9e4796c57 100644 --- a/backend/vehicles/src/modules/vehicles/trailers/trailers.controller.ts +++ b/backend/vehicles/src/modules/vehicles/trailers/trailers.controller.ts @@ -32,6 +32,8 @@ import { Roles } from '../../../common/decorator/roles.decorator'; import { Role } from '../../../common/enum/roles.enum'; import { DeleteDto } from 'src/modules/common/dto/response/delete.dto'; import { DeleteTrailerDto } from './dto/request/delete-trailer.dto'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; +import { getDirectory } from 'src/common/helper/auth.helper'; @ApiTags('Vehicles - Trailers') @ApiBadRequestResponse({ @@ -66,7 +68,14 @@ export class TrailersController { @Param('companyId') companyId: number, @Body() createTrailerDto: CreateTrailerDto, ) { - return this.trailersService.create(companyId, createTrailerDto); + const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); + return this.trailersService.create( + companyId, + createTrailerDto, + currentUser, + directory, + ); } @ApiOkResponse({ @@ -112,11 +121,15 @@ export class TrailersController { @Param('trailerId') trailerId: string, @Body() updateTrailerDto: UpdateTrailerDto, ): Promise { + const currentUser = request.user as IUserJWT; + const directory = getDirectory(currentUser); await this.checkVehicleCompanyContext(companyId, trailerId); const trailer = await this.trailersService.update( companyId, trailerId, updateTrailerDto, + currentUser, + directory, ); if (!trailer) { throw new DataNotFoundException(); diff --git a/backend/vehicles/src/modules/vehicles/trailers/trailers.service.ts b/backend/vehicles/src/modules/vehicles/trailers/trailers.service.ts index 6544cb472..8348bc427 100644 --- a/backend/vehicles/src/modules/vehicles/trailers/trailers.service.ts +++ b/backend/vehicles/src/modules/vehicles/trailers/trailers.service.ts @@ -8,6 +8,8 @@ import { ReadTrailerDto } from './dto/response/read-trailer.dto'; import { UpdateTrailerDto } from './dto/request/update-trailer.dto'; import { Trailer } from './entities/trailer.entity'; import { DeleteDto } from 'src/modules/common/dto/response/delete.dto'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; +import { Directory } from 'src/common/enum/directory.enum'; @Injectable() export class TrailersService { @@ -20,13 +22,21 @@ export class TrailersService { async create( companyId: number, trailer: CreateTrailerDto, + currentUser: IUserJWT, + directory: Directory, ): Promise { const newTrailer = this.classMapper.map( trailer, CreateTrailerDto, Trailer, { - extraArgs: () => ({ companyId: companyId }), + extraArgs: () => ({ + companyId: companyId, + userName: currentUser.userName, + directory: directory, + userGUID: currentUser.userGUID, + timestamp: new Date(), + }), }, ); return this.classMapper.mapAsync( @@ -71,11 +81,21 @@ export class TrailersService { companyId: number, trailerId: string, updateTrailerDto: UpdateTrailerDto, + currentUser: IUserJWT, + directory: Directory, ): Promise { const newTrailer = this.classMapper.map( updateTrailerDto, UpdateTrailerDto, Trailer, + { + extraArgs: () => ({ + userName: currentUser.userName, + directory: directory, + userGUID: currentUser.userGUID, + timestamp: new Date(), + }), + }, ); await this.trailerRepository.update( diff --git a/backend/vehicles/test/e2e/pending-idir-users.e2e-spec.ts b/backend/vehicles/test/e2e/pending-idir-users.e2e-spec.ts index b04b86cc3..0a37550f3 100644 --- a/backend/vehicles/test/e2e/pending-idir-users.e2e-spec.ts +++ b/backend/vehicles/test/e2e/pending-idir-users.e2e-spec.ts @@ -13,6 +13,8 @@ import { readPendingIdirUserMock, } from 'test/util/mocks/data/pending-idir-user.mock'; import { PendingIdirUsersModule } from 'src/modules/company-user-management/pending-idir-users/pending-idir-users.module'; +import { TestUserMiddleware } from './test-user.middleware'; +import { redCompanyAdminUserJWTMock } from 'test/util/mocks/data/jwt.mock'; const repo = createMock>(); @@ -34,6 +36,8 @@ describe('PendingUsers (e2e)', () => { .compile(); app = moduleFixture.createNestApplication(); + TestUserMiddleware.testUser = redCompanyAdminUserJWTMock; + app.use(TestUserMiddleware.prototype.use.bind(TestUserMiddleware)); await app.init(); }); diff --git a/backend/vehicles/test/e2e/power-units.e2e-spec.ts b/backend/vehicles/test/e2e/power-units.e2e-spec.ts index a24aabb09..278db4460 100644 --- a/backend/vehicles/test/e2e/power-units.e2e-spec.ts +++ b/backend/vehicles/test/e2e/power-units.e2e-spec.ts @@ -17,6 +17,8 @@ import { updatePowerUnitDtoMock, } from '../util/mocks/data/power-unit.mock'; import { deleteDtoFailureMock } from 'test/util/mocks/data/delete-dto.mock'; +import { TestUserMiddleware } from './test-user.middleware'; +import { redCompanyCvClientUserJWTMock } from 'test/util/mocks/data/jwt.mock'; describe('Power Units (e2e)', () => { let app: INestApplication; @@ -36,6 +38,8 @@ describe('Power Units (e2e)', () => { .compile(); app = moduleFixture.createNestApplication(); + TestUserMiddleware.testUser = redCompanyCvClientUserJWTMock; + app.use(TestUserMiddleware.prototype.use.bind(TestUserMiddleware)); await app.init(); }); diff --git a/backend/vehicles/test/e2e/trailers.e2e-spec.ts b/backend/vehicles/test/e2e/trailers.e2e-spec.ts index b0cd3994c..9af57dfa4 100644 --- a/backend/vehicles/test/e2e/trailers.e2e-spec.ts +++ b/backend/vehicles/test/e2e/trailers.e2e-spec.ts @@ -16,6 +16,8 @@ import { updateTrailerDtoMock, } from '../util/mocks/data/trailer.mock'; import { deleteDtoFailureMock } from 'test/util/mocks/data/delete-dto.mock'; +import { TestUserMiddleware } from './test-user.middleware'; +import { redCompanyCvClientUserJWTMock } from 'test/util/mocks/data/jwt.mock'; describe('Trailers (e2e)', () => { let app: INestApplication; @@ -35,6 +37,8 @@ describe('Trailers (e2e)', () => { .compile(); app = moduleFixture.createNestApplication(); + TestUserMiddleware.testUser = redCompanyCvClientUserJWTMock; + app.use(TestUserMiddleware.prototype.use.bind(TestUserMiddleware)); await app.init(); }); diff --git a/backend/vehicles/test/unit/company/company.controller.spec.ts b/backend/vehicles/test/unit/company/company.controller.spec.ts index 68e9dd78a..ec637d6db 100644 --- a/backend/vehicles/test/unit/company/company.controller.spec.ts +++ b/backend/vehicles/test/unit/company/company.controller.spec.ts @@ -142,6 +142,7 @@ describe('CompanyController', () => { extension: null, }); const retCompany = await controller.update( + request, constants.RED_COMPANY_ID, updateRedCompanyDtoMock, ); @@ -153,7 +154,11 @@ describe('CompanyController', () => { request.user = redCompanyAdminUserJWTMock; companyService.update.mockResolvedValue(undefined); await expect(async () => { - await controller.update(COMPANY_ID_99, updateRedCompanyDtoMock); + await controller.update( + request, + COMPANY_ID_99, + updateRedCompanyDtoMock, + ); }).rejects.toThrow(DataNotFoundException); }); }); diff --git a/backend/vehicles/test/unit/company/company.service.spec.ts b/backend/vehicles/test/unit/company/company.service.spec.ts index 94a7d9138..593f9ceed 100644 --- a/backend/vehicles/test/unit/company/company.service.spec.ts +++ b/backend/vehicles/test/unit/company/company.service.spec.ts @@ -15,7 +15,6 @@ import { dataSourceMockFactory, } from '../../util/mocks/factory/dataSource.factory.mock'; import { UsersProfile } from '../../../src/modules/company-user-management/users/profiles/user.profile'; -import { Directory } from '../../../src/common/enum/directory.enum'; import { AddressProfile } from '../../../src/modules/common/profiles/address.profile'; import { ContactProfile } from '../../../src/modules/common/profiles/contact.profile'; import { @@ -33,6 +32,7 @@ import * as constants from '../../util/mocks/data/test-data.constants'; import { blueCompanyAdminUserJWTMock, redCompanyAdminUserJWTMock, + redCompanyCvClientUserJWTMock, } from '../../util/mocks/data/jwt.mock'; import * as databaseHelper from 'src/common/helper/database.helper'; import { EmailService } from '../../../src/modules/email/email.service'; @@ -153,6 +153,7 @@ describe('CompanyService', () => { constants.RED_COMPANY_ID, updateRedCompanyDtoMock, constants.RED_COMPANY_DIRECOTRY, + redCompanyCvClientUserJWTMock, ); expect(typeof retCompany).toBe('object'); @@ -167,7 +168,8 @@ describe('CompanyService', () => { await service.update( COMPANY_ID_99, updateRedCompanyDtoMock, - Directory.BBCEID, + constants.RED_COMPANY_DIRECOTRY, + redCompanyCvClientUserJWTMock, ); }).rejects.toThrow(DataNotFoundException); }); diff --git a/backend/vehicles/test/unit/pending-idir-users/pending-idir-users.controller.spec.ts b/backend/vehicles/test/unit/pending-idir-users/pending-idir-users.controller.spec.ts index f613203f6..80c1bfa14 100644 --- a/backend/vehicles/test/unit/pending-idir-users/pending-idir-users.controller.spec.ts +++ b/backend/vehicles/test/unit/pending-idir-users/pending-idir-users.controller.spec.ts @@ -11,6 +11,8 @@ import { pendingIdirUserEntityMock, readPendingIdirUserMock, } from 'test/util/mocks/data/pending-idir-user.mock'; +import { getDirectory } from 'src/common/helper/auth.helper'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; let pendingIdirUserService: DeepMocked; @@ -44,14 +46,20 @@ describe('PendingIdirUsersController', () => { it('should create a company', async () => { const request = createMock(); request.user = sysAdminStaffUserJWTMock; + const currentUser = request.user as IUserJWT; pendingIdirUserService.create.mockResolvedValue(readPendingIdirUserMock); - const retPendingUser = await controller.create(createPendingIdirUserMock); + const retPendingUser = await controller.create( + request, + createPendingIdirUserMock, + ); expect(typeof retPendingUser).toBe('object'); expect(retPendingUser.userName).toEqual( constants.SYS_ADMIN_STAFF_USER_NAME, ); expect(pendingIdirUserService.create).toHaveBeenCalledWith( createPendingIdirUserMock, + getDirectory(currentUser), + currentUser, ); }); }); diff --git a/backend/vehicles/test/unit/pending-idir-users/pending-idir-users.service.spec.ts b/backend/vehicles/test/unit/pending-idir-users/pending-idir-users.service.spec.ts index 40377edca..8cb0d0986 100644 --- a/backend/vehicles/test/unit/pending-idir-users/pending-idir-users.service.spec.ts +++ b/backend/vehicles/test/unit/pending-idir-users/pending-idir-users.service.spec.ts @@ -13,6 +13,8 @@ import { pendingIdirUserEntityMock, } from 'test/util/mocks/data/pending-idir-user.mock'; import { PendingIdirUsersProfile } from 'src/modules/company-user-management/pending-idir-users/profiles/pending-idir-user.profile'; +import { getDirectory } from 'src/common/helper/auth.helper'; +import { sysAdminStaffUserJWTMock } from 'test/util/mocks/data/jwt.mock'; let repo: DeepMocked>; @@ -54,7 +56,11 @@ describe('PendingUsersService', () => { describe('Pending idir user service create function', () => { it('should create a Pending idir user.', async () => { repo.save.mockResolvedValue(pendingIdirUserEntityMock); - const retPendingUser = await service.create(createPendingIdirUserMock); + const retPendingUser = await service.create( + createPendingIdirUserMock, + getDirectory(sysAdminStaffUserJWTMock), + sysAdminStaffUserJWTMock, + ); expect(typeof retPendingUser).toBe('object'); }); }); diff --git a/backend/vehicles/test/unit/pending-users/pending-users.controller.spec.ts b/backend/vehicles/test/unit/pending-users/pending-users.controller.spec.ts index 3b22bf777..1341d4c5c 100644 --- a/backend/vehicles/test/unit/pending-users/pending-users.controller.spec.ts +++ b/backend/vehicles/test/unit/pending-users/pending-users.controller.spec.ts @@ -14,6 +14,7 @@ import { updateRedCompanyPendingUserDtoMock, } from '../../util/mocks/data/pending-user.mock'; import { UserAuthGroup } from '../../../src/common/enum/user-auth-group.enum'; +import { getDirectory } from 'src/common/helper/auth.helper'; const COMPANY_ID_99 = 99; let pendingUserService: DeepMocked; @@ -50,6 +51,7 @@ describe('PendingUsersController', () => { readRedCompanyPendingUserDtoMock, ); const retPendingUser = await controller.create( + request, constants.RED_COMPANY_ID, createRedCompanyPendingUserDtoMock, ); @@ -61,6 +63,8 @@ describe('PendingUsersController', () => { expect(pendingUserService.create).toHaveBeenCalledWith( constants.RED_COMPANY_ID, createRedCompanyPendingUserDtoMock, + getDirectory(redCompanyAdminUserJWTMock), + redCompanyAdminUserJWTMock, ); }); }); @@ -120,6 +124,7 @@ describe('PendingUsersController', () => { userAuthGroup: UserAuthGroup.COMPANY_ADMINISTRATOR, }); const retPendingUsers = await controller.update( + request, constants.RED_COMPANY_ID, constants.RED_COMPANY_PENDING_USER_NAME, updateRedCompanyPendingUserDtoMock, @@ -137,6 +142,7 @@ describe('PendingUsersController', () => { pendingUserService.update.mockResolvedValue(undefined); await expect(async () => { await controller.update( + request, COMPANY_ID_99, constants.RED_COMPANY_PENDING_USER_NAME, updateRedCompanyPendingUserDtoMock, diff --git a/backend/vehicles/test/unit/pending-users/pending-users.service.spec.ts b/backend/vehicles/test/unit/pending-users/pending-users.service.spec.ts index 3e1e8d2e3..9ba2613b6 100644 --- a/backend/vehicles/test/unit/pending-users/pending-users.service.spec.ts +++ b/backend/vehicles/test/unit/pending-users/pending-users.service.spec.ts @@ -16,6 +16,8 @@ import { import { createQueryBuilderMock } from '../../util/mocks/factory/dataSource.factory.mock'; import { UserAuthGroup } from '../../../src/common/enum/user-auth-group.enum'; import * as constants from '../../util/mocks/data/test-data.constants'; +import { redCompanyCvClientUserJWTMock } from 'test/util/mocks/data/jwt.mock'; +import { getDirectory } from 'src/common/helper/auth.helper'; interface SelectQueryBuilderParameters { userName?: string; @@ -70,6 +72,8 @@ describe('PendingUsersService', () => { const retPendingUser = await service.create( constants.RED_COMPANY_ID, createRedCompanyPendingUserDtoMock, + getDirectory(redCompanyCvClientUserJWTMock), + redCompanyCvClientUserJWTMock, ); expect(typeof retPendingUser).toBe('object'); expect(retPendingUser.companyId).toBe(constants.RED_COMPANY_ID); @@ -89,6 +93,8 @@ describe('PendingUsersService', () => { constants.RED_COMPANY_ID, constants.RED_COMPANY_PENDING_USER_NAME, updateRedCompanyPendingUserDtoMock, + getDirectory(redCompanyCvClientUserJWTMock), + redCompanyCvClientUserJWTMock, ); expect(typeof retPendingUser).toBe('object'); expect(retPendingUser.companyId).toBe(constants.RED_COMPANY_ID); diff --git a/backend/vehicles/test/unit/power-units/power-units.controller.spec.ts b/backend/vehicles/test/unit/power-units/power-units.controller.spec.ts index b9a25f69b..02693f856 100644 --- a/backend/vehicles/test/unit/power-units/power-units.controller.spec.ts +++ b/backend/vehicles/test/unit/power-units/power-units.controller.spec.ts @@ -10,6 +10,11 @@ import { } from '../../util/mocks/data/power-unit.mock'; import { powerUnitsServiceMock } from '../../util/mocks/service/power-units.service.mock'; import { deleteDtoMock } from '../../util/mocks/data/delete-dto.mock'; +import { createMock } from '@golevelup/ts-jest'; +import { Request } from 'express'; +import { redCompanyCvClientUserJWTMock } from 'test/util/mocks/data/jwt.mock'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; +import { getDirectory } from 'src/common/helper/auth.helper'; const POWER_UNIT_ID_1 = '1'; const POWER_UNIT_ID_2 = '2'; @@ -35,8 +40,11 @@ describe('PowerUnitsController', () => { describe('Power unit controller create function', () => { it('should create a power unit', async () => { + const request = createMock(); + request.user = redCompanyCvClientUserJWTMock; + const currentUser = request.user as IUserJWT; const retPowerUnit = await controller.create( - null, + request, COMPANY_ID_1, createPowerUnitDtoMock, ); @@ -45,6 +53,8 @@ describe('PowerUnitsController', () => { expect(powerUnitsServiceMock.create).toHaveBeenCalledWith( COMPANY_ID_1, createPowerUnitDtoMock, + currentUser, + getDirectory(currentUser), ); }); }); @@ -78,8 +88,12 @@ describe('PowerUnitsController', () => { describe('Power unit controller update function', () => { it('should update the power unit', async () => { + const request = createMock(); + request.user = redCompanyCvClientUserJWTMock; + const currentUser = request.user as IUserJWT; + const retPowerUnit = await controller.update( - null, + request, COMPANY_ID_1, POWER_UNIT_ID_1, updatePowerUnitDtoMock, @@ -93,13 +107,17 @@ describe('PowerUnitsController', () => { COMPANY_ID_1, POWER_UNIT_ID_1, updatePowerUnitDtoMock, + currentUser, + getDirectory(currentUser), ); }); it('should thrown a DataNotFoundException if the power unit does not exist', async () => { await expect(async () => { + const request = createMock(); + request.user = redCompanyCvClientUserJWTMock; await controller.update( - null, + request, COMPANY_ID_1, POWER_UNIT_ID_2, updatePowerUnitDtoMock, diff --git a/backend/vehicles/test/unit/power-units/power-units.service.spec.ts b/backend/vehicles/test/unit/power-units/power-units.service.spec.ts index ae3e9e1e7..b8751da31 100644 --- a/backend/vehicles/test/unit/power-units/power-units.service.spec.ts +++ b/backend/vehicles/test/unit/power-units/power-units.service.spec.ts @@ -13,6 +13,8 @@ import { powerUnitEntityMock, updatePowerUnitDtoMock, } from '../../util/mocks/data/power-unit.mock'; +import { getDirectory } from 'src/common/helper/auth.helper'; +import { redCompanyCvClientUserJWTMock } from 'test/util/mocks/data/jwt.mock'; const COMPANY_ID_1 = 1; const POWER_UNIT_ID_1 = '1'; @@ -54,6 +56,8 @@ describe('PowerUnitsService', () => { const retPowerUnit = await service.create( COMPANY_ID_1, createPowerUnitDtoMock, + redCompanyCvClientUserJWTMock, + getDirectory(redCompanyCvClientUserJWTMock), ); expect(typeof retPowerUnit).toBe('object'); expect(retPowerUnit.powerUnitId).toBe(POWER_UNIT_ID_1); @@ -88,6 +92,8 @@ describe('PowerUnitsService', () => { COMPANY_ID_1, POWER_UNIT_ID_1, updatePowerUnitDtoMock, + redCompanyCvClientUserJWTMock, + getDirectory(redCompanyCvClientUserJWTMock), ); expect(typeof retPowerUnit).toBe('object'); expect(retPowerUnit.powerUnitId).toBe(POWER_UNIT_ID_1); diff --git a/backend/vehicles/test/unit/trailers/trailers.controller.spec.ts b/backend/vehicles/test/unit/trailers/trailers.controller.spec.ts index 933ab8693..e72a3cb6a 100644 --- a/backend/vehicles/test/unit/trailers/trailers.controller.spec.ts +++ b/backend/vehicles/test/unit/trailers/trailers.controller.spec.ts @@ -10,6 +10,11 @@ import { } from '../../util/mocks/data/trailer.mock'; import { trailersServiceMock } from '../../util/mocks/service/trailers.service.mock'; import { deleteDtoMock } from '../../util/mocks/data/delete-dto.mock'; +import { createMock } from '@golevelup/ts-jest'; +import { Request } from 'express'; +import { redCompanyCvClientUserJWTMock } from 'test/util/mocks/data/jwt.mock'; +import { IUserJWT } from 'src/common/interface/user-jwt.interface'; +import { getDirectory } from 'src/common/helper/auth.helper'; const TRAILER_ID_1 = '1'; const TRAILER_ID_2 = '2'; @@ -32,8 +37,11 @@ describe('TrailersController', () => { }); describe('Trailer controller create function', () => { it('should create trailer', async () => { + const request = createMock(); + request.user = redCompanyCvClientUserJWTMock; + const currentUser = request.user as IUserJWT; const retTrailer = await controller.create( - null, + request, COMPANY_ID_1, createTrailerDtoMock, ); @@ -42,6 +50,8 @@ describe('TrailersController', () => { expect(trailersServiceMock.create).toHaveBeenCalledWith( COMPANY_ID_1, createTrailerDtoMock, + currentUser, + getDirectory(currentUser), ); }); }); @@ -75,8 +85,12 @@ describe('TrailersController', () => { describe('Trailer controller update function', () => { it('should update the trailer', async () => { + const request = createMock(); + request.user = redCompanyCvClientUserJWTMock; + const currentUser = request.user as IUserJWT; + const retTrailer = await controller.update( - null, + request, COMPANY_ID_1, TRAILER_ID_1, updateTrailerDtoMock, @@ -87,13 +101,17 @@ describe('TrailersController', () => { COMPANY_ID_1, TRAILER_ID_1, updateTrailerDtoMock, + currentUser, + getDirectory(currentUser), ); }); it('should thrown a DataNotFoundException if the trailer is not found', async () => { await expect(async () => { + const request = createMock(); + request.user = redCompanyCvClientUserJWTMock; await controller.update( - null, + request, COMPANY_ID_1, TRAILER_ID_2, updateTrailerDtoMock, diff --git a/backend/vehicles/test/unit/trailers/trailers.service.spec.ts b/backend/vehicles/test/unit/trailers/trailers.service.spec.ts index bb8f969de..4fd15f9d2 100644 --- a/backend/vehicles/test/unit/trailers/trailers.service.spec.ts +++ b/backend/vehicles/test/unit/trailers/trailers.service.spec.ts @@ -13,6 +13,8 @@ import { trailerEntityMock, updateTrailerDtoMock, } from '../../util/mocks/data/trailer.mock'; +import { redCompanyCvClientUserJWTMock } from 'test/util/mocks/data/jwt.mock'; +import { getDirectory } from 'src/common/helper/auth.helper'; const COMPANY_ID_1 = 1; const TRAILER_ID_1 = '1'; @@ -54,6 +56,8 @@ describe('TrailersService', () => { const retTrailer = await service.create( COMPANY_ID_1, createTrailerDtoMock, + redCompanyCvClientUserJWTMock, + getDirectory(redCompanyCvClientUserJWTMock), ); expect(typeof retTrailer).toBe('object'); expect(retTrailer.trailerId).toBe(TRAILER_ID_1); @@ -88,6 +92,8 @@ describe('TrailersService', () => { COMPANY_ID_1, TRAILER_ID_1, updateTrailerDtoMock, + redCompanyCvClientUserJWTMock, + getDirectory(redCompanyCvClientUserJWTMock), ); expect(typeof retTrailer).toBe('object'); expect(retTrailer.trailerId).toBe(TRAILER_ID_1); diff --git a/backend/vehicles/test/unit/users/company-users.controller.spec.ts b/backend/vehicles/test/unit/users/company-users.controller.spec.ts index cf49bedb3..a29babd06 100644 --- a/backend/vehicles/test/unit/users/company-users.controller.spec.ts +++ b/backend/vehicles/test/unit/users/company-users.controller.spec.ts @@ -91,6 +91,7 @@ describe('CompanyUsersController', () => { constants.RED_COMPANY_CVCLIENT_USER_GUID, updateRedCompanyCvClientUserDtoMock, constants.RED_COMPANY_ID, + getDirectory(redCompanyAdminUserJWTMock), request.user, ); }); diff --git a/backend/vehicles/test/unit/users/users.service.spec.ts b/backend/vehicles/test/unit/users/users.service.spec.ts index dd63e0a26..f2ce60a8d 100644 --- a/backend/vehicles/test/unit/users/users.service.spec.ts +++ b/backend/vehicles/test/unit/users/users.service.spec.ts @@ -46,6 +46,8 @@ import { PendingIdirUsersService } from 'src/modules/company-user-management/pen import { pendingIdirUserEntityMock } from 'test/util/mocks/data/pending-idir-user.mock'; import { Request } from 'express'; import { IUserJWT } from '../../../src/common/interface/user-jwt.interface'; +import { Directory } from 'src/common/enum/directory.enum'; +import { getDirectory } from 'src/common/helper/auth.helper'; interface SelectQueryBuilderParameters { userGUID?: string; @@ -182,6 +184,7 @@ describe('UsersService', () => { constants.RED_COMPANY_CVCLIENT_USER_GUID, updateRedCompanyCvClientUserDtoMock, constants.RED_COMPANY_ID, + getDirectory(redCompanyCvClientUserJWTMock), request.user as IUserJWT, ); @@ -221,6 +224,8 @@ describe('UsersService', () => { const retUpdateResult = await service.updateStatus( constants.BLUE_COMPANY_CVCLIENT_USER_GUID, UserStatus.DISABLED, + Directory.BCEID, + redCompanyCvClientUserJWTMock, ); expect(typeof retUpdateResult).toBe('object'); expect(retUpdateResult.affected).toBe(1); diff --git a/backend/vehicles/test/util/mocks/data/base.mock.ts b/backend/vehicles/test/util/mocks/data/base.mock.ts index dc46f8b5b..3181f5529 100644 --- a/backend/vehicles/test/util/mocks/data/base.mock.ts +++ b/backend/vehicles/test/util/mocks/data/base.mock.ts @@ -3,24 +3,29 @@ import { Base } from '../../../../src/modules/common/entities/base.entity'; const CURRENT_DATE = new Date(); const CURRENT_DATE_ISO_STRING = CURRENT_DATE.toISOString(); -const CONCURRENCY_CONTROL_NUMBER = 1; const CREATED_USER = 'USER'; const CREATED_DATE_TIME = CURRENT_DATE; const UPDATED_USER = 'USER'; const UPDATED_DATE_TIME = CURRENT_DATE; export const baseEntityMock: Base = { - concurrencyControlNumber: CONCURRENCY_CONTROL_NUMBER, createdUser: CREATED_USER, + createdUserDirectory: CREATED_USER, + createdUserGuid: CREATED_USER, createdDateTime: CREATED_DATE_TIME, updatedUser: UPDATED_USER, + updatedUserGuid: UPDATED_USER, + updatedUserDirectory: UPDATED_USER, updatedDateTime: UPDATED_DATE_TIME, }; export const baseDtoMock: BaseDto = { - concurrencyControlNumber: CONCURRENCY_CONTROL_NUMBER, createdUser: CREATED_USER, + createdUserDirectory: CREATED_USER, + createdUserGuid: CREATED_USER, createdDateTime: CURRENT_DATE_ISO_STRING, updatedUser: UPDATED_USER, + updatedUserGuid: UPDATED_USER, + updatedUserDirectory: UPDATED_USER, updatedDateTime: CURRENT_DATE_ISO_STRING, }; diff --git a/database/mssql/scripts/versions/v_2_ddl.sql b/database/mssql/scripts/versions/v_2_ddl.sql index 0dd1e4d0a..93e8e701a 100644 --- a/database/mssql/scripts/versions/v_2_ddl.sql +++ b/database/mssql/scripts/versions/v_2_ddl.sql @@ -16,6 +16,14 @@ CREATE TABLE [dbo].[ORBC_POWER_UNIT]( [LICENSED_GVW] [numeric](18, 2) NULL, [POWER_UNIT_TYPE_CODE] [char](7) NOT NULL, [STEER_AXLE_TIRE_SIZE] [int] NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -38,6 +46,14 @@ CREATE TABLE [dbo].[ORBC_TRAILER]( [VIN] [char](6) NOT NULL, [TRAILER_TYPE_CODE] [char](7) NOT NULL, [EMPTY_TRAILER_WIDTH] [numeric](18, 2) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, diff --git a/database/mssql/scripts/versions/v_3_ddl.sql b/database/mssql/scripts/versions/v_3_ddl.sql index fdf370b46..3ba22b70a 100644 --- a/database/mssql/scripts/versions/v_3_ddl.sql +++ b/database/mssql/scripts/versions/v_3_ddl.sql @@ -15,6 +15,14 @@ CREATE TABLE [dbo].[ORBC_ADDRESS]( [CITY] [nvarchar](100) NOT NULL, [PROVINCE_ID] [char](5) NOT NULL, [POSTAL_CODE] [varchar](7) NOT NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -35,6 +43,14 @@ CREATE TABLE [dbo].[ORBC_IDIR_USER]( [EMAIL] [nvarchar](100) NOT NULL, [STATUS_CODE] [varchar](10) NOT NULL, [USER_AUTH_GROUP_ID] [varchar](10) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -62,6 +78,14 @@ CREATE TABLE [dbo].[ORBC_COMPANY]( [PRIMARY_CONTACT_ID] [int] NULL, [ACCOUNT_REGION] [char](1) NULL, [ACCOUNT_SOURCE] [char](1) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -93,6 +117,14 @@ CREATE TABLE [dbo].[ORBC_COMPANY_USER]( [COMPANY_ID] [int] NOT NULL, [USER_GUID] [char](32) NOT NULL, [USER_AUTH_GROUP_ID] [varchar](10) NOT NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -117,6 +149,14 @@ CREATE TABLE [dbo].[ORBC_CONTACT]( [FAX] [varchar](20) NULL, [CITY] [nvarchar](100) NOT NULL, [PROVINCE_ID] [char](5) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -133,6 +173,14 @@ CREATE TABLE [access].[ORBC_GROUP_ROLE]( [GROUP_ROLE_ID] [int] IDENTITY(1,1) NOT NULL, [USER_AUTH_GROUP_ID] [varchar](10) NOT NULL, [ROLE_ID] [varchar](50) NOT NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -149,6 +197,14 @@ CREATE TABLE [dbo].[ORBC_PENDING_USER]( [COMPANY_ID] [int] NOT NULL, [USERNAME] [varchar](50) NOT NULL, [USER_AUTH_GROUP_ID] [varchar](10) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -165,6 +221,14 @@ GO CREATE TABLE [dbo].[ORBC_PENDING_IDIR_USER]( [USERNAME] [varchar](50) NOT NULL, [USER_AUTH_GROUP_ID] [varchar](10) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -184,6 +248,14 @@ CREATE TABLE [dbo].[ORBC_USER]( [STATUS_CODE] [varchar](10) NOT NULL, [CONTACT_ID] [int] NOT NULL, [USER_AUTH_GROUP_ID] [varchar](10) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -713,4 +785,4 @@ GO DECLARE @VersionDescription VARCHAR(255) SET @VersionDescription = 'Initial creation of schema entities for manage profile feature' -INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (3, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate()) +INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (3, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate()) \ No newline at end of file diff --git a/database/mssql/scripts/versions/v_4_ddl.sql b/database/mssql/scripts/versions/v_4_ddl.sql index 296b46f26..b361b3547 100644 --- a/database/mssql/scripts/versions/v_4_ddl.sql +++ b/database/mssql/scripts/versions/v_4_ddl.sql @@ -26,6 +26,14 @@ CREATE TABLE [permit].[ORBC_PERMIT]( [PERMIT_VOID_DATE_TIME] [datetime2](7) NULL, [DOCUMENT_ID] [varchar](10) NULL, [COMMENT] [nvarchar](3000), + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -45,6 +53,14 @@ CREATE TABLE [permit].[ORBC_PERMIT_COMMENTS]( [INTERNAL_ONLY] [bit] NOT NULL, [USER_GUID] [char](32) NULL, [COMMENT_DATE] [datetime2](7) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -63,6 +79,14 @@ CREATE TABLE [permit].[ORBC_PERMIT_DATA]( [PERMIT_DATA] [nvarchar](4000) NULL, [START_DATE] AS (json_value([PERMIT_DATA],'$.startDate')), [EXPIRY_DATE] AS (json_value([PERMIT_DATA],'$.expiryDate')), + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -81,6 +105,14 @@ CREATE TABLE [permit].[ORBC_PERMIT_STATE]( [PERMIT_STATUS_ID] [varchar](20) NULL, [STATE_CHANGE_DATE] [datetime2](7) NULL, [USER_GUID] [char](32) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, diff --git a/database/mssql/scripts/versions/v_5_ddl.sql b/database/mssql/scripts/versions/v_5_ddl.sql index 04af89998..be442b069 100644 --- a/database/mssql/scripts/versions/v_5_ddl.sql +++ b/database/mssql/scripts/versions/v_5_ddl.sql @@ -13,6 +13,14 @@ CREATE TABLE [dops].[ORBC_DOCUMENT_TEMPLATE]( [TEMPLATE_NAME] [varchar](50) NOT NULL, [TEMPLATE_VERSION] [int] NOT NULL, [DOCUMENT_ID] [varchar](50) NOT NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, diff --git a/database/mssql/scripts/versions/v_6_ddl.sql b/database/mssql/scripts/versions/v_6_ddl.sql index 03dabc563..f0393b1e4 100644 --- a/database/mssql/scripts/versions/v_6_ddl.sql +++ b/database/mssql/scripts/versions/v_6_ddl.sql @@ -14,6 +14,14 @@ CREATE TABLE [dops].[ORBC_DOCUMENT]( [FILE_NAME] [varchar](50) NOT NULL, [DMS_VERSION_ID] [int] NOT NULL, [COMPANY_ID] [int] NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, @@ -57,6 +65,14 @@ CREATE TABLE [dops].[ORBC_EXTERNAL_DOCUMENT]( [DOCUMENT_LOCATION] [varchar](200) NOT NULL, [DOCUMENT_MIME_TYPE] [varchar](200) NOT NULL, [DOCUMENT_VERSION_ID] [int] NOT NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NOT NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NOT NULL, diff --git a/database/mssql/scripts/versions/v_7_ddl.sql b/database/mssql/scripts/versions/v_7_ddl.sql index ab5d20cbd..0d82f2de1 100644 --- a/database/mssql/scripts/versions/v_7_ddl.sql +++ b/database/mssql/scripts/versions/v_7_ddl.sql @@ -41,6 +41,14 @@ CREATE TABLE [permit].[ORBC_TRANSACTION]( [PAYMENT_METHOD_ID] [int] NULL, [MESSAGE_ID] [int] NULL, [MESSAGE_TEXT] [varchar](100) NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NULL, @@ -58,6 +66,14 @@ CREATE TABLE [permit].[ORBC_RECEIPT]( [RECEIPT_NUMBER] [varchar](19) NOT NULL, [TRANSACTION_ID] [bigint] NOT NULL, [RECEIPT_DOCUMENT_ID] [varchar](10) NOT NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NULL, @@ -80,6 +96,14 @@ CREATE TABLE [permit].[ORBC_PERMIT_TRANSACTION]( [ID] [bigint] IDENTITY(1,1) NOT NULL, [PERMIT_ID] [bigint] NOT NULL, [TRANSACTION_ID] [bigint] NOT NULL, + [APP_CREATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_CREATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_CREATE_USER_GUID] [char](32) NULL, + [APP_CREATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_TIMESTAMP] [datetime2](7) DEFAULT (getutcdate()), + [APP_LAST_UPDATE_USERID] [nvarchar](30) DEFAULT (user_name()), + [APP_LAST_UPDATE_USER_GUID] [char](32) NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] [nvarchar](30) DEFAULT (user_name()), [CONCURRENCY_CONTROL_NUMBER] [int] NULL, [DB_CREATE_USERID] [varchar](63) NULL, [DB_CREATE_TIMESTAMP] [datetime2](7) NULL,