Skip to content

Commit efb4752

Browse files
committed
Very minor changes
tsDoc, function names, Array to []
1 parent c1dfeb6 commit efb4752

10 files changed

Lines changed: 39 additions & 53 deletions

File tree

app/src/controllers/contact.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const searchContactsController = async (
7171
res.status(200).json(response);
7272
};
7373

74-
export const updateContactController = async (req: Request<never, never, Contact, never>, res: Response) => {
74+
export const upsertContactController = async (req: Request<never, never, Contact, never>, res: Response) => {
7575
const contact = { ...req.body, contactId: req.body.contactId ?? uuidv4() };
7676
const response = await transactionWrapper<Contact[]>(async (tx: PrismaTransactionClient) => {
7777
return await upsertContacts(tx, [{ ...contact, ...generateUpdateStamps(req.currentContext) }]);

app/src/db/extensions/filterDeleted.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const findOperations: readonly string[] = [
1010
];
1111

1212
/*
13-
* Can't seem to get these param types from Prisma
13+
* args is some crazy dynamic type
1414
*/
1515

1616
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17-
function filterActivity(operation: any, args: any) {
17+
function filterActivity(operation: string, args: any) {
1818
if (findOperations.includes(operation)) {
1919
args.where = args.where
2020
? { AND: [args.where, { activity: { isDeleted: false } }] }
@@ -25,7 +25,7 @@ function filterActivity(operation: any, args: any) {
2525
}
2626

2727
// eslint-disable-next-line @typescript-eslint/no-explicit-any
28-
function filterColumn(operation: any, args: any) {
28+
function filterColumn(operation: string, args: any) {
2929
if (findOperations.includes(operation)) {
3030
args.where = args.where ? { AND: [args.where, { isDeleted: false }] } : { isDeleted: false };
3131
}

app/src/db/extensions/numeric.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
11
import { Prisma } from '@prisma/client';
2-
// import { castInput } from '../utils/utils';
3-
4-
// const NUMERIC_PRISMA_TYPES = ['Decimal'];
52

63
const numericTransform = Prisma.defineExtension({
7-
// query: {
8-
// $allModels: {
9-
// $allOperations({ model, operation, args, query }) {
10-
// // Cast input data for all prisma operations from ISO string to Date
11-
// if (operation === 'create' || operation === 'update') {
12-
// if ('data' in args) castInput(model, args.data, NUMERIC_PRISMA_TYPES);
13-
// }
14-
15-
// if (operation === 'upsert') {
16-
// const { create, update } = args;
17-
// castInput(model, create, NUMERIC_PRISMA_TYPES);
18-
// castInput(model, update, NUMERIC_PRISMA_TYPES);
19-
// }
20-
21-
// if (operation === 'createMany' || operation === 'updateMany') {
22-
// if ('data' in args) {
23-
// const d = args.data;
24-
// Array.isArray(d)
25-
// ? d.forEach((row) => castInput(model, row, NUMERIC_PRISMA_TYPES))
26-
// : castInput(model, d, NUMERIC_PRISMA_TYPES);
27-
// }
28-
// }
29-
30-
// return query(args);
31-
// }
32-
// }
33-
// },
344
result: {
355
document: {
366
filesize: {

app/src/db/prisma/schema.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ model permit_note {
192192
permitNoteId String @id @map("permit_note_id") @db.Uuid
193193
permitId String @map("permit_id") @db.Uuid
194194
note String @default("")
195-
isDeleted Boolean @default(false) @map("is_deleted")
196195
createdBy String? @default("00000000-0000-0000-0000-000000000000") @map("created_by")
197196
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
198197
updatedBy String? @map("updated_by")
199198
updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
199+
isDeleted Boolean @default(false) @map("is_deleted")
200200
permit permit @relation(fields: [permitId], references: [permitId], onDelete: Cascade, map: "permit_note_permit_id_foreign")
201201
202202
@@schema("public")
@@ -669,11 +669,11 @@ model note_history {
669669
updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
670670
bringForwardDate DateTime? @map("bring_forward_date") @db.Timestamptz(6)
671671
bringForwardState String? @map("bring_forward_state")
672-
isDeleted Boolean @default(false) @map("is_deleted")
673672
shownToProponent Boolean @default(false) @map("shown_to_proponent")
674673
escalateToSupervisor Boolean @default(false) @map("escalate_to_supervisor")
675674
escalateToDirector Boolean @default(false) @map("escalate_to_director")
676675
escalationType String? @map("escalation_type") @db.VarChar(255)
676+
isDeleted Boolean @default(false) @map("is_deleted")
677677
note note[]
678678
activity activity @relation(fields: [activityId], references: [activityId], onDelete: Cascade, map: "note_activity_id_foreign")
679679

app/src/db/utils/utils.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,35 @@ export async function checkDatabaseSchema(): Promise<boolean> {
7474
return matches.tables;
7575
}
7676

77+
/**
78+
* Generates DB create stamps
79+
* @param currentContext The current context of the Express request
80+
* @returns An object with filled create stamps
81+
*/
7782
export function generateCreateStamps(currentContext: CurrentContext | undefined) {
7883
return {
7984
createdBy: currentContext?.userId ?? NIL,
8085
createdAt: new Date()
8186
};
8287
}
8388

89+
/**
90+
* Generates DB update stamps
91+
* @param currentContext The current context of the Express request
92+
* @returns An object with filled update stamps
93+
*/
8494
export function generateUpdateStamps(currentContext: CurrentContext | undefined) {
8595
return {
8696
updatedBy: (currentContext?.userId as string) ?? NIL,
8797
updatedAt: new Date()
8898
};
8999
}
90100

101+
/**
102+
* Generates null DB update stamps
103+
* @param currentContext The current context of the Express request
104+
* @returns An object with null update stamps
105+
*/
91106
export function generateNullUpdateStamps() {
92107
return {
93108
updatedBy: null,
@@ -98,9 +113,10 @@ export function generateNullUpdateStamps() {
98113
/**
99114
* Generate a new activityId, which are truncated UUIDs
100115
* If a collision is detected, generate new UUID and test again
116+
* @param tx Prisma transaction client
101117
* @returns A string in title case
102118
*/
103-
export async function generateUniqueActivityId(tx: PrismaTransactionClient) {
119+
export async function generateUniqueActivityId(tx: PrismaTransactionClient): Promise<string> {
104120
let id, queryResult;
105121

106122
do {
@@ -112,7 +128,7 @@ export async function generateUniqueActivityId(tx: PrismaTransactionClient) {
112128
return id;
113129
}
114130

115-
export function jsonToPrismaInputJson(json: Prisma.JsonValue) {
131+
export function jsonToPrismaInputJson(json: Prisma.JsonValue): Prisma.NullTypes.JsonNull | Prisma.InputJsonValue {
116132
if (json === null) return null as unknown as Prisma.JsonNullValueInput;
117133
return json as Prisma.InputJsonValue;
118134
}

app/src/routes/v1/contact.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
getCurrentUserContactController,
77
matchContactsController,
88
searchContactsController,
9-
updateContactController
9+
upsertContactController
1010
} from '../../controllers/contact';
1111
import { hasAuthorization } from '../../middleware/authorization';
1212
import { requireSomeAuth } from '../../middleware/requireSomeAuth';
@@ -49,8 +49,8 @@ router.get(
4949
router.put(
5050
'/',
5151
hasAuthorization(Resource.CONTACT, Action.UPDATE),
52-
contactValidator.updateContact,
53-
updateContactController
52+
contactValidator.upsertContact,
53+
upsertContactController
5454
);
5555

5656
/** Delete a specific contact */

app/src/utils/cache/codes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const log = getLogger(module.filename);
1818
export async function refreshCodeCaches(): Promise<boolean> {
1919
try {
2020
const codeTables = await transactionWrapper<{
21-
ElectrificationProjectType: Array<ElectrificationProjectTypeCode>;
22-
ElectrificationProjectCategory: Array<ElectrificationProjectCategoryCode>;
23-
SourceSystem: Array<SourceSystemCode>;
21+
ElectrificationProjectType: ElectrificationProjectTypeCode[];
22+
ElectrificationProjectCategory: ElectrificationProjectCategoryCode[];
23+
SourceSystem: SourceSystemCode[];
2424
}>(async (tx: PrismaTransactionClient) => {
2525
return await listAllCodeTables(tx);
2626
});

app/src/validators/contact.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const schema = {
6565
includeActivities: Joi.boolean().default(false)
6666
})
6767
},
68-
updateContact: {
68+
upsertContact: {
6969
body: Joi.object({
7070
userId: uuidv4.allow(null),
7171
contactId: uuidv4.allow(null),
@@ -89,5 +89,5 @@ export default {
8989
getContactActivities: validate(schema.getContact),
9090
matchContacts: validate(schema.matchContacts),
9191
searchContacts: validate(schema.searchContacts),
92-
updateContact: validate(schema.updateContact)
92+
upsertContact: validate(schema.upsertContact)
9393
};

app/tests/unit/controllers/contact.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
deleteContactController,
66
getContactController,
77
searchContactsController,
8-
updateContactController
8+
upsertContactController
99
} from '../../../src/controllers/contact';
1010
import { Contact, ContactSearchParameters } from '../../../src/types';
1111
import { uuidv4Pattern } from '../../../src/utils/regexp';
@@ -200,7 +200,7 @@ describe('updateContactController', () => {
200200

201201
upsertContactsSpy.mockResolvedValueOnce([TEST_CONTACT_1]);
202202

203-
await updateContactController(
203+
await upsertContactController(
204204
req as unknown as Request<never, never, Contact, never>,
205205
res as unknown as Response
206206
);
@@ -233,7 +233,7 @@ describe('updateContactController', () => {
233233

234234
upsertContactsSpy.mockResolvedValueOnce([TEST_CONTACT_1]);
235235

236-
await updateContactController(
236+
await upsertContactController(
237237
req as unknown as Request<never, never, Contact, never>,
238238
res as unknown as Response
239239
);

frontend/src/components/housing/submission/SubmissionIntakeForm.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,14 @@ async function onSubmit(data: any) {
310310
contactPreference: data.contacts.contactPreference
311311
};
312312
313+
// Omit all the fields we dont want to send
314+
const dataOmitted = omit(setEmptyStringsToNull({ ...data }), ['contacts']);
315+
313316
// Show the trackingNumber of all appliedPermits to the proponent
314-
data.appliedPermits?.forEach((x: Permit) => {
317+
dataOmitted.appliedPermits?.forEach((x: Permit) => {
315318
if (x?.permitTracking?.[0]) x.permitTracking[0].shownToProponent = true;
316319
});
317320
318-
// Omit all the fields we dont want to send
319-
const dataOmitted = omit(setEmptyStringsToNull({ ...data }), ['contacts']);
320-
321321
// Remove empty investigate permit objects
322322
const filteredInvestigatePermits = dataOmitted.investigatePermits?.filter(
323323
(x: object) => JSON.stringify(x) !== '{}'

0 commit comments

Comments
 (0)