Skip to content

Commit

Permalink
Update user files
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoHernandez92 committed May 18, 2024
1 parent 77b5310 commit 9ff059d
Show file tree
Hide file tree
Showing 43 changed files with 24 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export const startApp = (app: Express, prisma: PrismaClient) => {

const usersRepo = new UserRepository(prisma);
const usersController = new UserController(usersRepo);
const usersRouter = new UserRouter(usersController, authInterceptor);
const usersRouter = new UserRouter(
usersController,
authInterceptor,
filesMiddleware
);
app.use('/users', usersRouter.router);

const projectsRepo = new ProjectRepository(prisma);
Expand Down
6 changes: 6 additions & 0 deletions src/controllers/users.controller/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@ export class UserController extends BaseController<
next(error);
}
}

async update(req: Request, res: Response, next: NextFunction) {
req.body.imageUrl = req.body.archive as string;
delete req.body.archive;
await super.update(req, res, next);
}
}
1 change: 0 additions & 1 deletion src/middleware/auth.middleware/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export class AuthMiddleware {
return;
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/files.middleware/files.middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Given a instance of the class FilesInterceptor', () => {
});

test('Then it should call Multer middleware', () => {
interceptor.uploadFile()(req, res, next);
interceptor.uploadFile('')(req, res, next);
expect(mockMiddleware).toHaveBeenCalled();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/files.middleware/files.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class FilesMiddleware {
debug('Instantiated files interceptor');
}

uploadFile(fieldName = 'archive') {
uploadFile(fieldName: string) {
debug('Creating file middleware');
const storage = multer.diskStorage({
destination: 'uploads/',
Expand Down
12 changes: 6 additions & 6 deletions src/routers/projects.router/project.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ export class ProjectRouter {

this.router.patch(
'/:id',
authMiddleware.authentication.bind(authMiddleware),
authMiddleware.authorization(projectRepo, 'author').bind(authMiddleware),
// FfilesMiddleware.uploadFile('archive').bind(filesMiddleware),
// filesMiddleware.cloudinaryUpload.bind(filesMiddleware),
// AauthMiddleware.authentication.bind(authMiddleware),
// authMiddleware.authorization(projectRepo, 'author').bind(authMiddleware),
filesMiddleware.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),
// A authMiddleware.authentication.bind(authMiddleware),
// authMiddleware.authorization(projectRepo, 'author').bind(authMiddleware),
projectController.delete.bind(projectController)
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/routers/users.routers/user.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type UserController } from '../../controllers/users.controller/users.co
import { Router as createRouter } from 'express';
import createDebug from 'debug';
import { type AuthMiddleware } from '../../middleware/auth.middleware/auth.middleware';
import { type FilesMiddleware } from '../../middleware/files.middleware/files.middleware';

const debug = createDebug('FP*:router');

Expand All @@ -10,7 +11,8 @@ export class UserRouter {

constructor(
protected readonly userController: UserController,
protected authMiddleware: AuthMiddleware
protected authMiddleware: AuthMiddleware,
protected filesMiddleware: FilesMiddleware
) {
debug('instantiated user router');

Expand All @@ -28,6 +30,8 @@ export class UserRouter {
this.router.patch(
'/:id',
// AauthMiddleware.authentication.bind(authMiddleware),
filesMiddleware.uploadFile('archive').bind(filesMiddleware),
filesMiddleware.cloudinaryUpload.bind(filesMiddleware),
userController.update.bind(userController)
);

Expand Down
Binary file added uploads/1715859476522_descarga.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/1715864673437_estadistica.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/1715874969298_angular.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/1715884545982_estadistica.jpg
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/1715953004419_guitarra.jpg
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/1715955700823_descarga.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/1715958598914_angular.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/1715959782196_guitarra.jpg
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/1715959841150_guitarra.jpg
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/1715960625804_angular.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/1716013180820_descarga.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/1716013323667_angular.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/1716013654583_angular.png
Binary file added uploads/1716013796939_angular.png
Binary file added uploads/1716027866847_descarga.png
Binary file added uploads/1716028081571_updatefile.jpg
Binary file added uploads/1716028758771_updatefile.jpg
Binary file added uploads/1716029874705_descarga.png
Binary file added uploads/1716033462659_updatefile.jpg
Binary file added uploads/1716033608020_estadistica.jpg
Binary file added uploads/1716034011537_updatefile.jpg
Binary file added uploads/1716034694542_estadistica.jpg
Binary file added uploads/1716035954969_updatefile.jpg

0 comments on commit 9ff059d

Please sign in to comment.