-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from bcgov/feat/log-notes
feat: adding functionality for notes to be added in a log
- Loading branch information
Showing
25 changed files
with
558 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as chefsController } from './chefs'; | ||
export { default as documentController } from './document'; | ||
export { default as noteController } from './note'; | ||
export { default as permitController } from './permit'; | ||
export { default as userController } from './user'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { NIL } from 'uuid'; | ||
|
||
import { noteService, userService } from '../services'; | ||
import { getCurrentIdentity } from '../components/utils'; | ||
|
||
import type { NextFunction, Request, Response } from '../interfaces/IExpress'; | ||
|
||
const controller = { | ||
createNote: async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, NIL), NIL); | ||
|
||
// TODO: define body type in request | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const body = req.body as any; | ||
const response = await noteService.createNote({ ...body, createdBy: userId }); | ||
res.status(200).send(response); | ||
} catch (e: unknown) { | ||
next(e); | ||
} | ||
}, | ||
|
||
async listNotes(req: Request<{ submissionId: string }>, res: Response, next: NextFunction) { | ||
try { | ||
const response = await noteService.listNotes(req.params.submissionId); | ||
res.status(200).send(response); | ||
} catch (e: unknown) { | ||
next(e); | ||
} | ||
} | ||
}; | ||
|
||
export default controller; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Prisma } from '@prisma/client'; | ||
import { default as submission } from './submission'; | ||
|
||
import type { ChefsSubmissionForm, Note } from '../../types'; | ||
|
||
// Define types | ||
const _note = Prisma.validator<Prisma.noteDefaultArgs>()({}); | ||
const _noteWithGraph = Prisma.validator<Prisma.noteDefaultArgs>()({ | ||
include: { submission: { include: { user: true } } } | ||
}); | ||
|
||
type SubmissionRelation = { | ||
submission: { | ||
connect: { | ||
submissionId: string; | ||
}; | ||
}; | ||
}; | ||
|
||
type PrismaRelationNote = Omit<Prisma.noteGetPayload<typeof _note>, 'submission_id'> & SubmissionRelation; | ||
|
||
type PrismaGraphNote = Prisma.noteGetPayload<typeof _noteWithGraph>; | ||
|
||
export default { | ||
toPrismaModel(input: Note): PrismaRelationNote { | ||
// Note: submissionId conversion to submission_id will be required here | ||
return { | ||
note_id: input.noteId as string, | ||
note: input.note, | ||
note_type: input.noteType, | ||
submission: { connect: { submissionId: input.submissionId } }, | ||
title: input.title, | ||
createdAt: input.createdAt ? new Date(input.createdAt) : null, | ||
createdBy: input.createdBy as string, | ||
updatedAt: input.updatedAt ? new Date(input.updatedAt) : null, | ||
updatedBy: input.updatedBy as string | ||
}; | ||
}, | ||
|
||
fromPrismaModel(input: PrismaGraphNote | null): Note | null { | ||
if (!input) return null; | ||
|
||
return { | ||
noteId: input.note_id, | ||
note: input.note || '', | ||
noteType: input.note_type || '', | ||
submission: submission.fromPrismaModel(input.submission) as ChefsSubmissionForm, | ||
submissionId: input.submission_id as string, | ||
title: input.title || '', | ||
createdAt: input.createdAt?.toISOString() ?? null, | ||
createdBy: input.createdBy, | ||
updatedAt: input.updatedAt?.toISOString() ?? null, | ||
updatedBy: input.updatedBy | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import express from 'express'; | ||
import { noteController } from '../../controllers'; | ||
import { requireSomeAuth } from '../../middleware/requireSomeAuth'; | ||
|
||
import type { NextFunction, Request, Response } from '../../interfaces/IExpress'; | ||
|
||
const router = express.Router(); | ||
router.use(requireSomeAuth); | ||
|
||
// note create endpoint | ||
router.put('/', (req: Request, res: Response, next: NextFunction): void => { | ||
noteController.createNote(req, res, next); | ||
}); | ||
|
||
// note list by submission endpoint | ||
router.get('/list/:submissionId', (req: Request, res: Response, next: NextFunction): void => { | ||
noteController.listNotes(req, res, next); | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as chefsService } from './chefs'; | ||
export { default as documentService } from './document'; | ||
export { default as noteService } from './note'; | ||
export { default as permitService } from './permit'; | ||
export { default as userService } from './user'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import prisma from '../db/dataConnection'; | ||
import { note } from '../db/models'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import type { Note } from '../types'; | ||
|
||
const service = { | ||
/** | ||
* @function createNote | ||
* Creates a note | ||
* @param data Note Object | ||
* @param identityId string | ||
* @returns {Promise<object>} The result of running the findUnique operation | ||
*/ | ||
createNote: async (data: Note) => { | ||
const newNote = { | ||
...data, | ||
noteId: uuidv4() | ||
}; | ||
const create = await prisma.note.create({ | ||
include: { | ||
submission: { | ||
include: { user: true } | ||
} | ||
}, | ||
data: note.toPrismaModel(newNote) | ||
}); | ||
|
||
return note.fromPrismaModel(create); | ||
}, | ||
|
||
/** | ||
* @function listNotes | ||
* Retrieve a list of permits associated with a given submission | ||
* @param submissionId PCNS Submission ID | ||
* @returns {Promise<object>} Array of documents associated with the submission | ||
*/ | ||
listNotes: async (submissionId: string) => { | ||
const response = await prisma.note.findMany({ | ||
include: { | ||
submission: { | ||
include: { user: true } | ||
} | ||
}, | ||
orderBy: { | ||
createdAt: 'desc' | ||
}, | ||
where: { | ||
submission_id: submissionId | ||
} | ||
}); | ||
return response.map((x) => note.fromPrismaModel(x)); | ||
} | ||
}; | ||
|
||
export default service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { IStamps } from '../interfaces/IStamps'; | ||
import type { ChefsSubmissionForm } from './ChefsSubmissionForm'; | ||
|
||
export type Note = { | ||
noteId: string; // Primary Key | ||
submissionId: string; | ||
note: string; | ||
noteType: string; | ||
submission: ChefsSubmissionForm; | ||
title: string; | ||
} & Partial<IStamps>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.