Skip to content

Commit 966941d

Browse files
committed
refactor: migrate to native uuid functions
Signed-off-by: Sanjay Babu <sanjaytkbabu@gmail.com>
1 parent 31f9098 commit 966941d

20 files changed

Lines changed: 50 additions & 73 deletions

app/src/controllers/contact.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from 'uuid';
1+
import { randomUUID } from 'node:crypto';
22

33
import {
44
deleteContactService,
@@ -76,7 +76,7 @@ export const upsertContactController = async (
7676
req: Request<never, never, Contact, never>,
7777
res: Response<Contact, LocalContext>
7878
) => {
79-
const contact = { ...req.body, contactId: req.body.contactId ?? uuidv4() };
79+
const contact = { ...req.body, contactId: req.body.contactId ?? randomUUID() };
8080
const response = await upsertContactsService([contact]);
8181
res.status(200).json(response[0]);
8282
};

app/src/db/migrations/20231212000000_init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* eslint-disable max-len */
22
import { randomUUID } from 'node:crypto';
33

4-
import { NIL_UUID } from '../../utils/constants/application.ts';
54
import { addAuditStamps } from '../utils/migrations/helpers.ts';
65

76
import type { Knex } from 'knex';
87

8+
const NIL_UUID = '00000000-0000-0000-0000-000000000000';
9+
910
export async function up(knex: Knex): Promise<void> {
1011
return (
1112
Promise.resolve()

app/src/db/migrations/20251027000000_044-system-id-change.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { NIL_UUID, SYSTEM_ID } from '../../utils/constants/application.ts';
1+
import { SYSTEM_ID } from '../../utils/constants/application.ts';
22

33
import type { Knex } from 'knex';
44

5+
const NIL_UUID = '00000000-0000-0000-0000-000000000000';
6+
57
export async function up(knex: Knex): Promise<void> {
68
return Promise.resolve()
79
.then(() => {

app/src/domains/activity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from 'uuid';
1+
import { randomUUID } from 'node:crypto';
22

33
import { Initiative } from '../utils/enums/application.ts';
44

@@ -19,7 +19,7 @@ export const createActivity = async (
1919
let id, queryResult;
2020

2121
do {
22-
id = uuidv4().substring(0, 8).toUpperCase();
22+
id = randomUUID().substring(0, 8).toUpperCase();
2323
queryResult = await repositories.activity.findUnique({
2424
where: { activityId: id },
2525
select: { activityId: true }

app/src/domains/electrificationProject.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from 'uuid';
1+
import { randomUUID } from 'node:crypto';
22

33
import { createActivity } from './activity';
44
import { Initiative } from '../utils/enums/application';
@@ -43,7 +43,7 @@ export const generateElectrificationProjectData = async (
4343
if (!activityId) throw new Error('Failed to generate activity ID');
4444

4545
// Put new electrification project together
46-
const UUID = uuidv4();
46+
const UUID = randomUUID();
4747

4848
const electrificationProjectData: ElectrificationProjectBase = {
4949
companyIdRegistered: data.basic?.registeredId ?? null,

app/src/domains/enquiry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import config from 'config';
2-
import { v4 as uuidv4 } from 'uuid';
2+
import { randomUUID } from 'node:crypto';
33

44
import { createActivity } from './activity';
55
import { getProjectByActivityId } from './project';
@@ -118,7 +118,7 @@ export const generateEnquiryData = async (
118118

119119
// Put new enquiry together
120120
return {
121-
enquiryId: data.enquiryId ?? uuidv4(),
121+
enquiryId: data.enquiryId ?? randomUUID(),
122122
activityId: activityId,
123123
relatedActivityId: data.relatedActivityId,
124124
enquiryDescription: data.enquiryDescription,

app/src/domains/generalProject.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from 'uuid';
1+
import { randomUUID } from 'node:crypto';
22

33
import { createActivity } from './activity';
44
import { PermitStage, PermitState } from '../db/codes/enums';
@@ -82,7 +82,7 @@ export const generateGeneralProjectData = async (
8282

8383
if (data.permits.appliedPermits?.length) {
8484
appliedPermits = data.permits.appliedPermits.map((x: Permit) => {
85-
const permitId = x.permitId ?? uuidv4();
85+
const permitId = x.permitId ?? randomUUID();
8686

8787
// Add each tracker for this permit with the proper permitId
8888
x.permitTracking?.forEach((pt) => appliedPermitTrackers.push({ ...pt, permitId }));
@@ -113,7 +113,7 @@ export const generateGeneralProjectData = async (
113113

114114
if (data.permits.investigatePermits?.length) {
115115
investigatePermits = data.permits.investigatePermits.map((x: Permit) => ({
116-
permitId: x.permitId ?? uuidv4(),
116+
permitId: x.permitId ?? randomUUID(),
117117
permitTypeId: x.permitTypeId,
118118
activityId: activityId,
119119
stage: PermitStage.PRE_SUBMISSION,
@@ -142,7 +142,7 @@ export const generateGeneralProjectData = async (
142142
...basic,
143143
...location,
144144
...permits,
145-
generalProjectId: uuidv4(),
145+
generalProjectId: randomUUID(),
146146
activityId: activityId,
147147
submittedAt: data.submittedAt ? new Date(data.submittedAt) : new Date(),
148148
applicationStatus: data.applicationStatus ?? ApplicationStatus.NEW,

app/src/domains/housingProject.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from 'uuid';
1+
import { randomUUID } from 'node:crypto';
22

33
import { createActivity } from './activity';
44
import { PermitStage, PermitState } from '../db/codes/enums';
@@ -150,7 +150,7 @@ export const generateHousingProjectData = async (
150150

151151
if (data.permits.appliedPermits?.length) {
152152
appliedPermits = data.permits.appliedPermits.map((x: Permit) => {
153-
const permitId = x.permitId ?? uuidv4();
153+
const permitId = x.permitId ?? randomUUID();
154154

155155
// Add each tracker for this permit with the proper permitId
156156
x.permitTracking?.forEach((pt) => appliedPermitTrackers.push({ ...pt, permitId }));
@@ -181,7 +181,7 @@ export const generateHousingProjectData = async (
181181

182182
if (data.permits.investigatePermits?.length) {
183183
investigatePermits = data.permits.investigatePermits.map((x: Permit) => ({
184-
permitId: x.permitId ?? uuidv4(),
184+
permitId: x.permitId ?? randomUUID(),
185185
permitTypeId: x.permitTypeId,
186186
activityId: activityId,
187187
stage: PermitStage.PRE_SUBMISSION,
@@ -211,7 +211,7 @@ export const generateHousingProjectData = async (
211211
...housing,
212212
...location,
213213
...permits,
214-
housingProjectId: uuidv4(),
214+
housingProjectId: randomUUID(),
215215
activityId: activityId,
216216
submittedAt: new Date(),
217217
submittedBy: getCurrentUsername(currentContext),

app/src/domains/permit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import config from 'config';
2-
import { v4 as uuidv4 } from 'uuid';
2+
import { randomUUID } from 'node:crypto';
33

44
import { getProjectByActivityId } from './project';
55
import { codeTable } from '../db/codes/cache';
@@ -132,7 +132,7 @@ export const sendPermitUpdateNotifications = async (
132132

133133
// Create update note for status change
134134
const permitNoteRes = await repositories.permitNote.create({
135-
permitNoteId: uuidv4(),
135+
permitNoteId: randomUUID(),
136136
permitId: permit.permitId,
137137
note: note ?? `This application is ${stateDisplay.toLocaleLowerCase()} in the ${stageDisplay.toLocaleLowerCase()}.`
138138
});

app/src/domains/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from 'uuid';
1+
import { randomUUID } from 'node:crypto';
22

33
import { DuplicateKeyProblem, NotFoundProblem } from '../db/errors';
44
import { JwtUser } from '../services/login';
@@ -17,7 +17,7 @@ export const createUser = async (
1717

1818
const newUser = {
1919
bceidBusinessName: data.bceidBusinessName ?? null,
20-
userId: uuidv4(),
20+
userId: randomUUID(),
2121
sub: data.sub,
2222
fullName: data.fullName,
2323
email: data.email,

0 commit comments

Comments
 (0)