diff --git a/src/app.ts b/src/app.ts index cc858bb..4c94659 100644 --- a/src/app.ts +++ b/src/app.ts @@ -39,7 +39,8 @@ export const startApp = (app: Express, prisma: PrismaClient) => { const projectsRouter = new ProjectRouter( projectsController, authInterceptor, - filesMiddleware + filesMiddleware, + projectsRepo ); app.use('/projects', projectsRouter.router); }; diff --git a/src/controllers/base.controller.ts b/src/controllers/base.controller.ts index 0623033..2fe57d1 100644 --- a/src/controllers/base.controller.ts +++ b/src/controllers/base.controller.ts @@ -24,7 +24,7 @@ export class BaseController { } async create(req: Request, res: Response, next: NextFunction) { - const data = req.body as C & Payload; + const data = req.body as C; try { const result = await this.repo.create(data); res.status(201); diff --git a/src/middleware/auth.middleware/auth.middleware.ts b/src/middleware/auth.middleware/auth.middleware.ts index 9927541..da361a2 100644 --- a/src/middleware/auth.middleware/auth.middleware.ts +++ b/src/middleware/auth.middleware/auth.middleware.ts @@ -56,6 +56,7 @@ export class AuthMiddleware { return; } + console.log(req.params.id); try { const item: T = await repo.readById(req.params.id); diff --git a/src/repositories/projects.repository/project.repository.ts b/src/repositories/projects.repository/project.repository.ts index de4f21e..375c1c5 100644 --- a/src/repositories/projects.repository/project.repository.ts +++ b/src/repositories/projects.repository/project.repository.ts @@ -57,7 +57,8 @@ export class ProjectRepository implements Repo { return newProject; } - async update(id: string, data: Partial) { + async update(id: string, data: Partial) { + const { payload, ...projectDto } = data; const project = await this.prisma.project.findUnique({ where: { id }, }); @@ -67,7 +68,7 @@ export class ProjectRepository implements Repo { return this.prisma.project.update({ where: { id }, - data, + data: projectDto, select, }); } diff --git a/src/routers/projects.router/project.router.ts b/src/routers/projects.router/project.router.ts index 3e17ece..c56f5e5 100644 --- a/src/routers/projects.router/project.router.ts +++ b/src/routers/projects.router/project.router.ts @@ -3,6 +3,7 @@ import createDebug from 'debug'; import { type AuthMiddleware } from '../../middleware/auth.middleware/auth.middleware.js'; import { type ProjectController } from '../../controllers/projects.controller/projects.controller.js'; import { type FilesMiddleware } from '../../middleware/files.middleware/files.middleware.js'; +import { type ProjectRepository } from '../../repositories/projects.repository/project.repository.js'; const debug = createDebug('FP*:router'); @@ -12,7 +13,8 @@ export class ProjectRouter { constructor( protected readonly projectController: ProjectController, protected authMiddleware: AuthMiddleware, - protected filesMiddleware: FilesMiddleware + protected filesMiddleware: FilesMiddleware, + protected projectRepo: ProjectRepository ) { debug('instantiated project router'); @@ -45,14 +47,17 @@ export class ProjectRouter { this.router.patch( '/:id', authMiddleware.authentication.bind(authMiddleware), - filesMiddleware.uploadFile('archive').bind(filesMiddleware), - filesMiddleware.cloudinaryUpload.bind(filesMiddleware), + authMiddleware.authorization(projectRepo, 'author').bind(authMiddleware), + // FfilesMiddleware.uploadFile('archive').bind(filesMiddleware), + // filesMiddleware.cloudinaryUpload.bind(filesMiddleware), + projectController.update.bind(projectController) ); this.router.delete( '/:id', authMiddleware.authentication.bind(authMiddleware), + authMiddleware.authorization(projectRepo, 'author').bind(authMiddleware), projectController.delete.bind(projectController) ); } diff --git a/uploads/1715187070720_react.png b/uploads/1715187070720_react.png new file mode 100644 index 0000000..77ff719 Binary files /dev/null and b/uploads/1715187070720_react.png differ diff --git a/uploads/1715187093423_react.png b/uploads/1715187093423_react.png new file mode 100644 index 0000000..77ff719 Binary files /dev/null and b/uploads/1715187093423_react.png differ diff --git a/uploads/1715187119363_react.png b/uploads/1715187119363_react.png new file mode 100644 index 0000000..77ff719 Binary files /dev/null and b/uploads/1715187119363_react.png differ diff --git a/uploads/1715187159289_react.png b/uploads/1715187159289_react.png new file mode 100644 index 0000000..77ff719 Binary files /dev/null and b/uploads/1715187159289_react.png differ