Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problems #13

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion src/controllers/base.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class BaseController<T, C> {
}

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);
Expand Down
1 change: 1 addition & 0 deletions src/middleware/auth.middleware/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class AuthMiddleware {
return;
}

console.log(req.params.id);
try {
const item: T = await repo.readById(req.params.id);

Expand Down
5 changes: 3 additions & 2 deletions src/repositories/projects.repository/project.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export class ProjectRepository implements Repo<Project, ProjectDto> {
return newProject;
}

async update(id: string, data: Partial<ProjectDto>) {
async update(id: string, data: Partial<ProjectDto & Payload>) {
const { payload, ...projectDto } = data;
const project = await this.prisma.project.findUnique({
where: { id },
});
Expand All @@ -67,7 +68,7 @@ export class ProjectRepository implements Repo<Project, ProjectDto> {

return this.prisma.project.update({
where: { id },
data,
data: projectDto,
select,
});
}
Expand Down
11 changes: 8 additions & 3 deletions src/routers/projects.router/project.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');

Expand Down Expand Up @@ -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)
);
}
Expand Down
Binary file added uploads/1715187070720_react.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added uploads/1715187093423_react.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added uploads/1715187119363_react.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added uploads/1715187159289_react.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading