-
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 #15 from bcgov/submission-docs-backend
Document upload
- Loading branch information
Showing
28 changed files
with
424 additions
and
34 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
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,39 @@ | ||
import { documentService } from '../services'; | ||
|
||
import type { NextFunction, Request, Response } from '../interfaces/IExpress'; | ||
|
||
const controller = { | ||
async createDocument( | ||
req: Request< | ||
never, | ||
never, | ||
{ documentId: string; submissionId: string; filename: string; mimeType: string; length: number } | ||
>, | ||
res: Response, | ||
next: NextFunction | ||
) { | ||
try { | ||
const response = await documentService.createDocument( | ||
req.body.documentId, | ||
req.body.submissionId, | ||
req.body.filename, | ||
req.body.mimeType, | ||
req.body.length | ||
); | ||
res.status(200).send(response); | ||
} catch (e: unknown) { | ||
next(e); | ||
} | ||
}, | ||
|
||
async listDocuments(req: Request<{ submissionId: string }>, res: Response, next: NextFunction) { | ||
try { | ||
const response = await documentService.listDocuments(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as chefsController } from './chefs'; | ||
export { default as documentController } from './document'; | ||
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 @@ | ||
# NR PermitConnect Navigator Service Database | ||
|
||
## Directory Structure | ||
|
||
```txt | ||
db/ - Database Root | ||
├── migrations/ - Knex database migrations files | ||
├── models/ - Database/Application conversion layer | ||
├── prisma/ - Location of the Prisma schema | ||
└── utils/ - Utility functions | ||
dataConnection.ts - Defines the Prisma database connection | ||
stamps.ts - Defines default timestamp columns | ||
``` | ||
|
||
## Models | ||
|
||
The files in `models/` contain two key sections: type definitions, and `toPrismaModel`/`fromPrismaModel` conversion functions. | ||
|
||
The type definitions are necessary to generate the appropriate hard typings for the conversions. They do not need to be exported as they should never need to be referenced outsite their respective files. | ||
|
||
Due to the way Prisma handles foreign keys multiple types may need to be created. | ||
|
||
Types beginning with `PrismaRelation` are type definitions for an object going to the database. This type may or may not include relational information, but for consistency are named with the same prefix. | ||
|
||
Types beginning with `PrismaGraph` are type definitions for an object coming from the database. The incoming type may also begin with `PrismaRelation` - it depends if there is any relational information required or not. | ||
|
||
See `user.ts` and `document.ts` for examples of the differences. | ||
|
||
The `toPrismaModel` and `fromPrismaModel` functions are used to convert Prisma database models to application `src/types/` and vice versa. These functions should only ever be used in the application service layer. | ||
|
||
## Future Considerations | ||
|
||
Consider the use of namespaces/modules to wrap particular sections of the application. As more initiatives are added to the system there will be naming conflicts. |
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,50 @@ | ||
import { Prisma } from '@prisma/client'; | ||
import disconnectRelation from '../utils/disconnectRelation'; | ||
|
||
import type { IStamps } from '../../interfaces/IStamps'; | ||
import type { Document } from '../../types'; | ||
|
||
// Define types | ||
const _document = Prisma.validator<Prisma.documentDefaultArgs>()({}); | ||
const _documentWithGraph = Prisma.validator<Prisma.documentDefaultArgs>()({}); | ||
|
||
type SubmissionRelation = { | ||
submission: | ||
| { | ||
connect: { | ||
submissionId: string; | ||
}; | ||
} | ||
| { | ||
disconnect: boolean; | ||
}; | ||
}; | ||
|
||
type PrismaRelationDocument = Omit<Prisma.documentGetPayload<typeof _document>, 'submissionId' | keyof IStamps> & | ||
SubmissionRelation; | ||
|
||
type PrismaGraphDocument = Prisma.documentGetPayload<typeof _documentWithGraph>; | ||
|
||
export default { | ||
toPrismaModel(input: Document): PrismaRelationDocument { | ||
return { | ||
documentId: input.documentId as string, | ||
filename: input.filename, | ||
mimeType: input.mimeType, | ||
filesize: BigInt(input.filesize), | ||
submission: input.submissionId ? { connect: { submissionId: input.submissionId } } : disconnectRelation | ||
}; | ||
}, | ||
|
||
fromPrismaModel(input: PrismaGraphDocument | null): Document | null { | ||
if (!input) return null; | ||
|
||
return { | ||
documentId: input.documentId, | ||
filename: input.filename, | ||
mimeType: input.mimeType, | ||
filesize: Number(input.filesize), | ||
submissionId: input.submissionId as string | ||
}; | ||
} | ||
}; |
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,3 +1,4 @@ | ||
export { default as document } from './document'; | ||
export { default as identity_provider } from './identity_provider'; | ||
export { default as submission } from './submission'; | ||
export { default as user } 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
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,18 @@ | ||
import express from 'express'; | ||
import { documentController } from '../../controllers'; | ||
import { requireSomeAuth } from '../../middleware/requireSomeAuth'; | ||
|
||
import type { NextFunction, Request, Response } from '../../interfaces/IExpress'; | ||
|
||
const router = express.Router(); | ||
router.use(requireSomeAuth); | ||
|
||
router.put('/', (req: Request, res: Response, next: NextFunction): void => { | ||
documentController.createDocument(req, res, next); | ||
}); | ||
|
||
router.get('/list/:submissionId', (req: Request, res: Response, next: NextFunction): void => { | ||
documentController.listDocuments(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
Oops, something went wrong.