From 0f0db5b24db6932585b24741625573fa92d16c62 Mon Sep 17 00:00:00 2001 From: Kevin Zhong <112502339+kevinzhong930@users.noreply.github.com> Date: Sun, 10 Nov 2024 09:29:01 -0500 Subject: [PATCH 1/4] Added standard endpoints for sticky notes Added standard endpoints for basic CRUD operations on the sticky market --- .../stickyNote/stickyNote.controller.ts | 78 +++++++++++++++++++ .../entities/stickyNote/stickyNote.model.ts | 24 ++++++ .../entities/stickyNote/stickyNote.router.ts | 26 +++++++ .../stickyNote/stickyNote.serializer.ts | 11 +++ .../entities/stickyNote/stickyNote.service.ts | 40 ++++++++++ .../stickyNote/stickyNote.validator.ts | 10 +++ .../1731177885475-add-sticky-notes.ts | 16 ++++ devU-api/src/router/courseData.router.ts | 6 ++ devU-shared/src/index.ts | 1 + devU-shared/src/types/stickyNote.types.ts | 5 ++ 10 files changed, 217 insertions(+) create mode 100644 devU-api/src/entities/stickyNote/stickyNote.controller.ts create mode 100644 devU-api/src/entities/stickyNote/stickyNote.model.ts create mode 100644 devU-api/src/entities/stickyNote/stickyNote.router.ts create mode 100644 devU-api/src/entities/stickyNote/stickyNote.serializer.ts create mode 100644 devU-api/src/entities/stickyNote/stickyNote.service.ts create mode 100644 devU-api/src/entities/stickyNote/stickyNote.validator.ts create mode 100644 devU-api/src/migration/1731177885475-add-sticky-notes.ts create mode 100644 devU-shared/src/types/stickyNote.types.ts diff --git a/devU-api/src/entities/stickyNote/stickyNote.controller.ts b/devU-api/src/entities/stickyNote/stickyNote.controller.ts new file mode 100644 index 0000000..ca6e3dd --- /dev/null +++ b/devU-api/src/entities/stickyNote/stickyNote.controller.ts @@ -0,0 +1,78 @@ +import {NextFunction, Request, Response} from 'express' + +import StickyNoteService from './stickyNote.service' + +import {NotFound, Updated} from '../../utils/apiResponse.utils' + +import {serialize} from './stickyNote.serializer' + +export async function retrieve(req: Request, res: Response, next: NextFunction) { + try { + const id = parseInt(req.params.id) + const stickyNote = await StickyNoteService.retrieve(id) + + if (!stickyNote) return res.status(404).json(NotFound) + + const response = serialize(stickyNote) + + res.status(200).json(response) + } catch (err) { + next(err) + } +} + +export async function post(req: Request, res: Response, next: NextFunction) { + try { + const reqStickyNote = req.body + const stickyNote = await StickyNoteService.create(reqStickyNote) + const response = serialize(stickyNote) + + res.status(201).json(response) + } catch (err) { + next(err) + } +} + +export async function put(req: Request, res: Response, next: NextFunction) { + try { + const reqStickyNote = req.body + const stickyNote = await StickyNoteService.update(reqStickyNote) + + if (!stickyNote.affected) return res.status(404).json(NotFound) + + res.status(200).json(Updated) + } catch (err) { + next(err) + } +} + +export async function remove(req: Request, res: Response, next: NextFunction) { + try { + const id = parseInt(req.params.id) + await StickyNoteService._delete(id) + + res.status(204).send() + } catch (err) { + next(err) + } +} + +export async function listBySubmission(req: Request, res: Response, next: NextFunction) { + try { + const submissionId = parseInt(req.params.submissionId) + const stickyNotes = await StickyNoteService.listBySubmission(submissionId) + const response = stickyNotes.map(serialize) + + res.status(200).json(response) + } catch (err) { + next(err) + } +} + +export default { + retrieve, + post, + put, + remove, + listBySubmission, +} \ No newline at end of file diff --git a/devU-api/src/entities/stickyNote/stickyNote.model.ts b/devU-api/src/entities/stickyNote/stickyNote.model.ts new file mode 100644 index 0000000..7eae455 --- /dev/null +++ b/devU-api/src/entities/stickyNote/stickyNote.model.ts @@ -0,0 +1,24 @@ +import { + JoinColumn, + ManyToOne, + Entity, + Column, + PrimaryGeneratedColumn, +} from 'typeorm' + +import SubmissionModel from '../submission/submission.model' + +@Entity('sticky_notes') +export default class StickyNotesModel { + + @PrimaryGeneratedColumn() + id: number + + @Column({ name: 'submissionId' }) + @JoinColumn({ name: 'submissionId' }) + @ManyToOne(() => SubmissionModel) + submissionId: number + + @Column({ name: 'content' }) + content: string +} \ No newline at end of file diff --git a/devU-api/src/entities/stickyNote/stickyNote.router.ts b/devU-api/src/entities/stickyNote/stickyNote.router.ts new file mode 100644 index 0000000..eff12bf --- /dev/null +++ b/devU-api/src/entities/stickyNote/stickyNote.router.ts @@ -0,0 +1,26 @@ +import express from 'express' + +// Middleware +import validator from './stickyNote.validator' +// import { isAuthorized } from '../../authorization/authorization.middleware' +import { asInt } from '../../middleware/validator/generic.validator' + +// Controller +import StickyNoteController from './stickyNote.controller' + +const Router = express.Router({ mergeParams: true }) + +Router.get('/:id' , asInt(), validator , StickyNoteController.retrieve) + +Router.post('/', validator, StickyNoteController.post) + +Router.put('/', validator, StickyNoteController.put) + +Router.delete('/:id', asInt(), validator, StickyNoteController.remove) + +Router.get('/all',validator , StickyNoteController.listBySubmission) + + +export default Router + + diff --git a/devU-api/src/entities/stickyNote/stickyNote.serializer.ts b/devU-api/src/entities/stickyNote/stickyNote.serializer.ts new file mode 100644 index 0000000..72b0cd7 --- /dev/null +++ b/devU-api/src/entities/stickyNote/stickyNote.serializer.ts @@ -0,0 +1,11 @@ +import {StickyNote} from 'devu-shared-modules' + +import StickyNoteModel from './stickyNote.model' + +export function serialize(stickyNote: StickyNoteModel): StickyNote { + return { + id: stickyNote.id, + submissionId: stickyNote.submissionId, + content: stickyNote.content, + } +} \ No newline at end of file diff --git a/devU-api/src/entities/stickyNote/stickyNote.service.ts b/devU-api/src/entities/stickyNote/stickyNote.service.ts new file mode 100644 index 0000000..6afe40b --- /dev/null +++ b/devU-api/src/entities/stickyNote/stickyNote.service.ts @@ -0,0 +1,40 @@ +// import {IsNull} from 'typeorm' +import {dataSource} from '../../database' + +import StickyNotesModel from './stickyNote.model' +import {StickyNote} from 'devu-shared-modules' + +const StickyNoteConn = () => dataSource.getRepository(StickyNotesModel) + +export async function create(stickyNote: StickyNote) { + return await StickyNoteConn().save(stickyNote) +} + +export async function update(stickyNote: StickyNote) { + const {id, submissionId, content} = stickyNote + if (!id) throw new Error('Missing Id') + return await StickyNoteConn().update(id, {submissionId, content}) +} + +export async function _delete(id: number) { +// return await StickyNoteConn().softDelete({id, deletedAt: IsNull()}) + return await StickyNoteConn().softDelete({id}) +} + +export async function retrieve(id: number) { +// return await StickyNoteConn().findOneBy({id, deletedAt: IsNull()}) + return await StickyNoteConn().findOneBy({id}) +} + +export async function listBySubmission(submissionId: number) { +// return await StickyNoteConn().findBy({submissionId :submissionId, deletedAt: IsNull()}) + return await StickyNoteConn().findBy({submissionId: submissionId}) +} + +export default { + create, + update, + _delete, + retrieve, + listBySubmission, +} \ No newline at end of file diff --git a/devU-api/src/entities/stickyNote/stickyNote.validator.ts b/devU-api/src/entities/stickyNote/stickyNote.validator.ts new file mode 100644 index 0000000..74902a4 --- /dev/null +++ b/devU-api/src/entities/stickyNote/stickyNote.validator.ts @@ -0,0 +1,10 @@ +import {check} from 'express-validator' + +import validate from '../../middleware/validator/generic.validator' + +const submissionId = check('submissionId').isNumeric() +const content = check('content').isString() + +const validator = [submissionId, content, validate] + +export default validator \ No newline at end of file diff --git a/devU-api/src/migration/1731177885475-add-sticky-notes.ts b/devU-api/src/migration/1731177885475-add-sticky-notes.ts new file mode 100644 index 0000000..a8f8e29 --- /dev/null +++ b/devU-api/src/migration/1731177885475-add-sticky-notes.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddStickyNotes1731177885475 implements MigrationInterface { + name = 'AddStickyNotes1731177885475' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "sticky_notes" ("id" SERIAL NOT NULL, "submissionId" integer NOT NULL, "content" character varying NOT NULL, CONSTRAINT "PK_615fc1d0c6b75c46aa2a7dd5f0a" PRIMARY KEY ("id"))`); + await queryRunner.query(`ALTER TABLE "sticky_notes" ADD CONSTRAINT "FK_a92bd7a1dc5c606db210b176a43" FOREIGN KEY ("submissionId") REFERENCES "submissions"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "sticky_notes" DROP CONSTRAINT "FK_a92bd7a1dc5c606db210b176a43"`); + await queryRunner.query(`DROP TABLE "sticky_notes"`); + } + +} diff --git a/devU-api/src/router/courseData.router.ts b/devU-api/src/router/courseData.router.ts index 174d0d7..c388ee8 100644 --- a/devU-api/src/router/courseData.router.ts +++ b/devU-api/src/router/courseData.router.ts @@ -14,13 +14,19 @@ import categoryScores from '../entities/categoryScore/categoryScore.router' import courseScores from '../entities/courseScore/courseScore.router' import assignmentScore from '../entities/assignmentScore/assignmentScore.router' import role from '../entities/role/role.router' +import stickyNotes from '../entities/stickyNote/stickyNote.router' import nonContainerAutoGraderRouter from '../entities/nonContainerAutoGrader/nonContainerAutoGrader.router' import { asInt } from '../middleware/validator/generic.validator' import webhooksRouter from '../entities/webhooks/webhooks.router' +const submissionRouter = express.Router({ mergeParams: true }) +submissionRouter.use('/sticky-notes', stickyNotes) + const assignmentRouter = express.Router({ mergeParams: true }) +assignmentRouter.use('/submission/:submissionId', asInt('submissionId'), submissionRouter) + assignmentRouter.use('/assignment-problems', assignmentProblem) assignmentRouter.use('/container-auto-graders', containerAutoGrader) assignmentRouter.use('/deadline-extensions', deadlineExtensions) diff --git a/devU-shared/src/index.ts b/devU-shared/src/index.ts index 464b8ba..20cc1a8 100644 --- a/devU-shared/src/index.ts +++ b/devU-shared/src/index.ts @@ -22,6 +22,7 @@ export * from './types/deadlineExtensions.types' export * from './types/grader.types' export * from './types/role.types' export * from './types/webhooks.types' +export * from './types/stickyNote.types' export * from './utils/object.utils' export * from './utils/string.utils' diff --git a/devU-shared/src/types/stickyNote.types.ts b/devU-shared/src/types/stickyNote.types.ts new file mode 100644 index 0000000..bf7cc76 --- /dev/null +++ b/devU-shared/src/types/stickyNote.types.ts @@ -0,0 +1,5 @@ +export type StickyNote = { + id?: number + submissionId: number + content: string +} \ No newline at end of file From a674275f79f1f92d6d497756d411d01285d22bb2 Mon Sep 17 00:00:00 2001 From: Kevin Zhong Date: Tue, 12 Nov 2024 11:10:51 -0500 Subject: [PATCH 2/4] Fixed up CRUD endpoints for sticky notes Fixed up CRUD endpoints for sticky notes so that they function as intended. --- .../entities/stickyNote/stickyNote.controller.ts | 4 +++- .../src/entities/stickyNote/stickyNote.model.ts | 4 ++++ .../src/entities/stickyNote/stickyNote.router.ts | 7 +++---- .../entities/stickyNote/stickyNote.service.ts | 8 ++++---- .../migration/1731177885475-add-sticky-notes.ts | 16 ---------------- .../1731427638811-add-sticky-note-endpoints.ts | 14 ++++++++++++++ 6 files changed, 28 insertions(+), 25 deletions(-) delete mode 100644 devU-api/src/migration/1731177885475-add-sticky-notes.ts create mode 100644 devU-api/src/migration/1731427638811-add-sticky-note-endpoints.ts diff --git a/devU-api/src/entities/stickyNote/stickyNote.controller.ts b/devU-api/src/entities/stickyNote/stickyNote.controller.ts index ca6e3dd..0fb707e 100644 --- a/devU-api/src/entities/stickyNote/stickyNote.controller.ts +++ b/devU-api/src/entities/stickyNote/stickyNote.controller.ts @@ -35,8 +35,10 @@ export async function post(req: Request, res: Response, next: NextFunction) { export async function put(req: Request, res: Response, next: NextFunction) { try { + const id = parseInt(req.params.id) const reqStickyNote = req.body - const stickyNote = await StickyNoteService.update(reqStickyNote) + // const stickyNote = await StickyNoteService.update(reqStickyNote) + const stickyNote = await StickyNoteService.update(id, reqStickyNote) if (!stickyNote.affected) return res.status(404).json(NotFound) diff --git a/devU-api/src/entities/stickyNote/stickyNote.model.ts b/devU-api/src/entities/stickyNote/stickyNote.model.ts index 7eae455..f6ce4c9 100644 --- a/devU-api/src/entities/stickyNote/stickyNote.model.ts +++ b/devU-api/src/entities/stickyNote/stickyNote.model.ts @@ -3,6 +3,7 @@ import { ManyToOne, Entity, Column, + DeleteDateColumn, PrimaryGeneratedColumn, } from 'typeorm' @@ -21,4 +22,7 @@ export default class StickyNotesModel { @Column({ name: 'content' }) content: string + + @DeleteDateColumn({ name: 'deleted_at' }) + deletedAt?: Date } \ No newline at end of file diff --git a/devU-api/src/entities/stickyNote/stickyNote.router.ts b/devU-api/src/entities/stickyNote/stickyNote.router.ts index eff12bf..35c016f 100644 --- a/devU-api/src/entities/stickyNote/stickyNote.router.ts +++ b/devU-api/src/entities/stickyNote/stickyNote.router.ts @@ -10,17 +10,16 @@ import StickyNoteController from './stickyNote.controller' const Router = express.Router({ mergeParams: true }) +Router.get('/all',validator , StickyNoteController.listBySubmission) + Router.get('/:id' , asInt(), validator , StickyNoteController.retrieve) Router.post('/', validator, StickyNoteController.post) -Router.put('/', validator, StickyNoteController.put) +Router.put('/:id', validator, StickyNoteController.put) Router.delete('/:id', asInt(), validator, StickyNoteController.remove) -Router.get('/all',validator , StickyNoteController.listBySubmission) - - export default Router diff --git a/devU-api/src/entities/stickyNote/stickyNote.service.ts b/devU-api/src/entities/stickyNote/stickyNote.service.ts index 6afe40b..e411fc3 100644 --- a/devU-api/src/entities/stickyNote/stickyNote.service.ts +++ b/devU-api/src/entities/stickyNote/stickyNote.service.ts @@ -1,4 +1,4 @@ -// import {IsNull} from 'typeorm' +import {IsNull} from 'typeorm' import {dataSource} from '../../database' import StickyNotesModel from './stickyNote.model' @@ -10,15 +10,15 @@ export async function create(stickyNote: StickyNote) { return await StickyNoteConn().save(stickyNote) } -export async function update(stickyNote: StickyNote) { - const {id, submissionId, content} = stickyNote +export async function update(id : number,stickyNote: StickyNote) { + const {submissionId, content} = stickyNote if (!id) throw new Error('Missing Id') return await StickyNoteConn().update(id, {submissionId, content}) } export async function _delete(id: number) { // return await StickyNoteConn().softDelete({id, deletedAt: IsNull()}) - return await StickyNoteConn().softDelete({id}) + return await StickyNoteConn().softDelete({id, deletedAt: IsNull()}) } export async function retrieve(id: number) { diff --git a/devU-api/src/migration/1731177885475-add-sticky-notes.ts b/devU-api/src/migration/1731177885475-add-sticky-notes.ts deleted file mode 100644 index a8f8e29..0000000 --- a/devU-api/src/migration/1731177885475-add-sticky-notes.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class AddStickyNotes1731177885475 implements MigrationInterface { - name = 'AddStickyNotes1731177885475' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE "sticky_notes" ("id" SERIAL NOT NULL, "submissionId" integer NOT NULL, "content" character varying NOT NULL, CONSTRAINT "PK_615fc1d0c6b75c46aa2a7dd5f0a" PRIMARY KEY ("id"))`); - await queryRunner.query(`ALTER TABLE "sticky_notes" ADD CONSTRAINT "FK_a92bd7a1dc5c606db210b176a43" FOREIGN KEY ("submissionId") REFERENCES "submissions"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "sticky_notes" DROP CONSTRAINT "FK_a92bd7a1dc5c606db210b176a43"`); - await queryRunner.query(`DROP TABLE "sticky_notes"`); - } - -} diff --git a/devU-api/src/migration/1731427638811-add-sticky-note-endpoints.ts b/devU-api/src/migration/1731427638811-add-sticky-note-endpoints.ts new file mode 100644 index 0000000..0b0100f --- /dev/null +++ b/devU-api/src/migration/1731427638811-add-sticky-note-endpoints.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddStickyNoteEndpoints1731427638811 implements MigrationInterface { + name = 'AddStickyNoteEndpoints1731427638811' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "sticky_notes" ADD "deleted_at" TIMESTAMP`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "sticky_notes" DROP COLUMN "deleted_at"`); + } + +} From e8371d013f8587288cf15e868842bbeedca1a2c2 Mon Sep 17 00:00:00 2001 From: Kevin Zhong Date: Tue, 12 Nov 2024 12:44:03 -0500 Subject: [PATCH 3/4] Added Authorization to the Sticky Notes router and updated Roles Added Authorization to the Sticky Notes router and updated Roles. --- devU-api/src/entities/role/role.defaults.ts | 4 ++++ devU-api/src/entities/role/role.model.ts | 6 ++++++ devU-api/src/entities/role/role.serializer.ts | 2 ++ .../src/entities/stickyNote/stickyNote.router.ts | 12 ++++++------ .../1731433278166-updatedRolesWithStickyNotes.ts | 16 ++++++++++++++++ devU-shared/src/types/role.types.ts | 2 ++ 6 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 devU-api/src/migration/1731433278166-updatedRolesWithStickyNotes.ts diff --git a/devU-api/src/entities/role/role.defaults.ts b/devU-api/src/entities/role/role.defaults.ts index dbf90ea..ffe5f7f 100644 --- a/devU-api/src/entities/role/role.defaults.ts +++ b/devU-api/src/entities/role/role.defaults.ts @@ -18,6 +18,8 @@ const student: Role = { submissionCreateAll: false, submissionCreateSelf: true, submissionViewAll: false, + stickyNoteViewAll: false, + stickyNoteEditAll: false, userCourseEditAll: false, } @@ -39,6 +41,8 @@ const instructor: Role = { submissionCreateAll: true, submissionCreateSelf: true, submissionViewAll: true, + stickyNoteViewAll: true, + stickyNoteEditAll: true, userCourseEditAll: true, } diff --git a/devU-api/src/entities/role/role.model.ts b/devU-api/src/entities/role/role.model.ts index 05a1341..76920b4 100644 --- a/devU-api/src/entities/role/role.model.ts +++ b/devU-api/src/entities/role/role.model.ts @@ -107,4 +107,10 @@ export default class RoleModel { @Column({ name: 'user_course_edit_all' }) // TODO: Don't let the last instructor change their role userCourseEditAll: boolean + + @Column({ name: 'sticky_note_view_all' }) + stickyNoteViewAll: boolean + + @Column({ name: 'sticky_note_edit_all' }) + stickyNoteEditAll: boolean } diff --git a/devU-api/src/entities/role/role.serializer.ts b/devU-api/src/entities/role/role.serializer.ts index ab6ead3..6b999ef 100644 --- a/devU-api/src/entities/role/role.serializer.ts +++ b/devU-api/src/entities/role/role.serializer.ts @@ -26,5 +26,7 @@ export function serialize(role: RoleModel): Role { submissionCreateSelf: role.submissionCreateSelf, submissionViewAll: role.submissionViewAll, userCourseEditAll: role.userCourseEditAll, + stickyNoteViewAll: role.stickyNoteViewAll, + stickyNoteEditAll: role.stickyNoteEditAll, } } diff --git a/devU-api/src/entities/stickyNote/stickyNote.router.ts b/devU-api/src/entities/stickyNote/stickyNote.router.ts index 35c016f..34dbf49 100644 --- a/devU-api/src/entities/stickyNote/stickyNote.router.ts +++ b/devU-api/src/entities/stickyNote/stickyNote.router.ts @@ -2,7 +2,7 @@ import express from 'express' // Middleware import validator from './stickyNote.validator' -// import { isAuthorized } from '../../authorization/authorization.middleware' +import { isAuthorized } from '../../authorization/authorization.middleware' import { asInt } from '../../middleware/validator/generic.validator' // Controller @@ -10,15 +10,15 @@ import StickyNoteController from './stickyNote.controller' const Router = express.Router({ mergeParams: true }) -Router.get('/all',validator , StickyNoteController.listBySubmission) +Router.get('/all', isAuthorized("stickyNoteViewAll"), validator , StickyNoteController.listBySubmission) -Router.get('/:id' , asInt(), validator , StickyNoteController.retrieve) +Router.get('/:id' ,isAuthorized("stickyNoteViewAll") , asInt("id"), validator , StickyNoteController.retrieve) -Router.post('/', validator, StickyNoteController.post) +Router.post('/',isAuthorized("stickyNoteEditAll") ,validator, StickyNoteController.post) -Router.put('/:id', validator, StickyNoteController.put) +Router.put('/:id',isAuthorized("stickyNoteEditAll") , validator, StickyNoteController.put) -Router.delete('/:id', asInt(), validator, StickyNoteController.remove) +Router.delete('/:id',isAuthorized("stickyNoteEditAll") , asInt("id"), validator, StickyNoteController.remove) export default Router diff --git a/devU-api/src/migration/1731433278166-updatedRolesWithStickyNotes.ts b/devU-api/src/migration/1731433278166-updatedRolesWithStickyNotes.ts new file mode 100644 index 0000000..c8e6636 --- /dev/null +++ b/devU-api/src/migration/1731433278166-updatedRolesWithStickyNotes.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdatedRolesWithStickyNotes1731433278166 implements MigrationInterface { + name = 'UpdatedRolesWithStickyNotes1731433278166' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "role" ADD "sticky_note_view_all" boolean NOT NULL`); + await queryRunner.query(`ALTER TABLE "role" ADD "sticky_note_edit_all" boolean NOT NULL`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "role" DROP COLUMN "sticky_note_edit_all"`); + await queryRunner.query(`ALTER TABLE "role" DROP COLUMN "sticky_note_view_all"`); + } + +} diff --git a/devU-shared/src/types/role.types.ts b/devU-shared/src/types/role.types.ts index 38c3e53..4877598 100644 --- a/devU-shared/src/types/role.types.ts +++ b/devU-shared/src/types/role.types.ts @@ -20,4 +20,6 @@ export type Role = { submissionCreateSelf: boolean submissionViewAll: boolean userCourseEditAll: boolean + stickyNoteViewAll: boolean + stickyNoteEditAll: boolean } From e5d7cd84be9b9fde47e7051555d400018b3587fc Mon Sep 17 00:00:00 2001 From: Kevin Zhong Date: Tue, 12 Nov 2024 12:48:59 -0500 Subject: [PATCH 4/4] Deleted comments and added deletedAt filtering Deleted Comments and Added deletedAt filtering --- devU-api/src/entities/stickyNote/stickyNote.controller.ts | 1 - devU-api/src/entities/stickyNote/stickyNote.service.ts | 7 ++----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/devU-api/src/entities/stickyNote/stickyNote.controller.ts b/devU-api/src/entities/stickyNote/stickyNote.controller.ts index 0fb707e..29aab12 100644 --- a/devU-api/src/entities/stickyNote/stickyNote.controller.ts +++ b/devU-api/src/entities/stickyNote/stickyNote.controller.ts @@ -37,7 +37,6 @@ export async function put(req: Request, res: Response, next: NextFunction) { try { const id = parseInt(req.params.id) const reqStickyNote = req.body - // const stickyNote = await StickyNoteService.update(reqStickyNote) const stickyNote = await StickyNoteService.update(id, reqStickyNote) if (!stickyNote.affected) return res.status(404).json(NotFound) diff --git a/devU-api/src/entities/stickyNote/stickyNote.service.ts b/devU-api/src/entities/stickyNote/stickyNote.service.ts index e411fc3..eca8b17 100644 --- a/devU-api/src/entities/stickyNote/stickyNote.service.ts +++ b/devU-api/src/entities/stickyNote/stickyNote.service.ts @@ -17,18 +17,15 @@ export async function update(id : number,stickyNote: StickyNote) { } export async function _delete(id: number) { -// return await StickyNoteConn().softDelete({id, deletedAt: IsNull()}) return await StickyNoteConn().softDelete({id, deletedAt: IsNull()}) } export async function retrieve(id: number) { -// return await StickyNoteConn().findOneBy({id, deletedAt: IsNull()}) - return await StickyNoteConn().findOneBy({id}) + return await StickyNoteConn().findOneBy({id, deletedAt: IsNull()}) } export async function listBySubmission(submissionId: number) { -// return await StickyNoteConn().findBy({submissionId :submissionId, deletedAt: IsNull()}) - return await StickyNoteConn().findBy({submissionId: submissionId}) + return await StickyNoteConn().findBy({submissionId: submissionId , deletedAt: IsNull()}) } export default {