update
This commit is contained in:
@ -57,6 +57,9 @@
|
|||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/express-fileupload": "^1.5.1",
|
"@types/express-fileupload": "^1.5.1",
|
||||||
"@types/morgan": "^1.9.9",
|
"@types/morgan": "^1.9.9",
|
||||||
"@types/swagger-ui-express": "^4.1.7"
|
"@types/swagger-ui-express": "^4.1.7",
|
||||||
|
"nodemon": "^3.1.14",
|
||||||
|
"ts-node": "^10.9.2",
|
||||||
|
"typescript": "^6.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ const log: Logger<ILogObj> = new Logger({
|
|||||||
name: "[UserController]",
|
name: "[UserController]",
|
||||||
type: "pretty",
|
type: "pretty",
|
||||||
});
|
});
|
||||||
|
const STORAGE_DIR = "assets/saude/";
|
||||||
|
|
||||||
export class UserController {
|
export class UserController {
|
||||||
static async list(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
static async list(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
@ -800,10 +801,10 @@ export class UserController {
|
|||||||
|
|
||||||
const ext = file.name.split(".");
|
const ext = file.name.split(".");
|
||||||
const name = uuidv4() + "." + ext[ext.length - 1];
|
const name = uuidv4() + "." + ext[ext.length - 1];
|
||||||
const file_path = path.join(folderPath, name);
|
const file_path = path.join(STORAGE_DIR, name);
|
||||||
|
|
||||||
if (!fs.existsSync(folderPath)) {
|
if (!fs.existsSync(STORAGE_DIR)) {
|
||||||
fs.mkdirSync(folderPath, { recursive: true });
|
fs.mkdirSync(STORAGE_DIR, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
await file.mv(file_path);
|
await file.mv(file_path);
|
||||||
@ -878,10 +879,10 @@ export class UserController {
|
|||||||
const data = await userRepository.findOneBy({ id: param.id });
|
const data = await userRepository.findOneBy({ id: param.id });
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
const doctorprofile = await UserController.uploadFile(req.files, "", "assets/saude");
|
const doctorprofile = await UserController.uploadFile(req.files, "", STORAGE_DIR);
|
||||||
if (doctorprofile) {
|
if (doctorprofile) {
|
||||||
if (data.profile_picture) {
|
if (data.profile_picture) {
|
||||||
const oldFilePath = path.join("assets/saude", data.profile_picture);
|
const oldFilePath = path.join(STORAGE_DIR, data.profile_picture);
|
||||||
await UserController.deleteFile(oldFilePath);
|
await UserController.deleteFile(oldFilePath);
|
||||||
}
|
}
|
||||||
data.profile_picture = doctorprofile;
|
data.profile_picture = doctorprofile;
|
||||||
@ -972,12 +973,12 @@ export class UserController {
|
|||||||
const data = await userRepository.findOneBy({ id: param.id });
|
const data = await userRepository.findOneBy({ id: param.id });
|
||||||
|
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
const usersignature = await UserController.uploadFile(req.files, "user_signature", "uploads/user-signature");
|
const usersignature = await UserController.uploadFile(req.files, "user_signature", STORAGE_DIR);
|
||||||
|
|
||||||
if (usersignature) {
|
if (usersignature) {
|
||||||
// ← Hapus signature lama jika ada
|
// ← Hapus signature lama jika ada
|
||||||
if (data.signature) {
|
if (data.signature) {
|
||||||
const oldFilePath = path.join("uploads/user-signature", data.signature);
|
const oldFilePath = path.join(STORAGE_DIR, data.signature);
|
||||||
await UserController.deleteFile(oldFilePath);
|
await UserController.deleteFile(oldFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user