update: room picture upload and hospital logo upload
This commit is contained in:
@ -176,18 +176,8 @@ export class HospitalInformationController {
|
|||||||
format: "binary",
|
format: "binary",
|
||||||
description: "Image file (max 1MB, jpg/png/webp)"
|
description: "Image file (max 1MB, jpg/png/webp)"
|
||||||
},
|
},
|
||||||
path: {
|
|
||||||
type: "string",
|
|
||||||
description: 'File path',
|
|
||||||
default: 'uploads/hospital-logo'
|
|
||||||
},
|
|
||||||
application: {
|
|
||||||
type: "string",
|
|
||||||
description: 'Application name',
|
|
||||||
default: 'saude'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
required: ["file", "path", "application"]
|
required: ["file"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,14 +185,14 @@ export class HospitalInformationController {
|
|||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
// Validation schema
|
// Validation schema
|
||||||
const schema = Joi.object().keys({
|
// const schema = Joi.object().keys({
|
||||||
path: Joi.string().label('File Path'),
|
// path: Joi.string().label('File Path'),
|
||||||
application: Joi.string().label('Application'),
|
// application: Joi.string().label('Application'),
|
||||||
});
|
// });
|
||||||
|
|
||||||
log.info("body", req.body);
|
log.info("body", req.body);
|
||||||
|
|
||||||
const param: { path: string, application: string } = await schema.validateAsync(req.body);
|
// const param: { path: string, application: string } = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
// Check if file exists
|
// Check if file exists
|
||||||
if (!req.files || !req.files.file) {
|
if (!req.files || !req.files.file) {
|
||||||
@ -224,9 +214,9 @@ export class HospitalInformationController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Normalize path
|
// Normalize path
|
||||||
param.path = param.path[param.path.length - 1] !== '/' ? param.path + '/' : param.path;
|
// param.path = param.path[param.path.length - 1] !== '/' ? param.path + '/' : param.path;
|
||||||
|
|
||||||
if (param.path == undefined || param.path == null) param.path = 'uploads/hospital-logo/';
|
// if (param.path == undefined || param.path == null) param.path = 'uploads/hospital-logo/';
|
||||||
|
|
||||||
// Generate unique filename
|
// Generate unique filename
|
||||||
const ext = file.name.split('.');
|
const ext = file.name.split('.');
|
||||||
@ -241,7 +231,7 @@ export class HospitalInformationController {
|
|||||||
// md5: file.md5
|
// md5: file.md5
|
||||||
};
|
};
|
||||||
|
|
||||||
const folder_path = param.path;
|
const folder_path ='uploads/hospital-logo/';
|
||||||
const file_path = path.join(folder_path, name);
|
const file_path = path.join(folder_path, name);
|
||||||
|
|
||||||
// Create directory if it doesn't exist
|
// Create directory if it doesn't exist
|
||||||
|
|||||||
@ -318,18 +318,8 @@ export class RoomController {
|
|||||||
format: "binary",
|
format: "binary",
|
||||||
description: "Image file (max 1MB, jpg/png/webp)"
|
description: "Image file (max 1MB, jpg/png/webp)"
|
||||||
},
|
},
|
||||||
path: {
|
|
||||||
type: "string",
|
|
||||||
description: 'File path',
|
|
||||||
default: 'uploads/room-picture'
|
|
||||||
},
|
|
||||||
application: {
|
|
||||||
type: "string",
|
|
||||||
description: 'Application name',
|
|
||||||
default: 'saude'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
required: ["file", "path", "application"]
|
required: ["file"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -338,13 +328,13 @@ export class RoomController {
|
|||||||
try {
|
try {
|
||||||
// Validation schema
|
// Validation schema
|
||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
path: Joi.string().label('File Path'),
|
// path: Joi.string().label('File Path'),
|
||||||
application: Joi.string().label('Application'),
|
// application: Joi.string().label('Application'),
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("body", req.body);
|
log.info("body", req.body);
|
||||||
|
|
||||||
const param: { path: string, application: string } = await schema.validateAsync(req.body);
|
// const param: { path: string, application: string } = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
// Check if file exists
|
// Check if file exists
|
||||||
if (!req.files || !req.files.file) {
|
if (!req.files || !req.files.file) {
|
||||||
@ -366,9 +356,9 @@ export class RoomController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Normalize path
|
// Normalize path
|
||||||
param.path = param.path[param.path.length - 1] !== '/' ? param.path + '/' : param.path;
|
// param.path = param.path[param.path.length - 1] !== '/' ? param.path + '/' : param.path;
|
||||||
|
|
||||||
if (param.path == undefined || param.path == null) param.path = 'uploads/room-picture/';
|
// if (param.path == undefined || param.path == null) param.path = 'uploads/room-picture/';
|
||||||
|
|
||||||
// Generate unique filename
|
// Generate unique filename
|
||||||
const ext = file.name.split('.');
|
const ext = file.name.split('.');
|
||||||
@ -383,7 +373,7 @@ export class RoomController {
|
|||||||
// md5: file.md5
|
// md5: file.md5
|
||||||
};
|
};
|
||||||
|
|
||||||
const folder_path = param.path;
|
const folder_path = 'uploads/room-picture/';
|
||||||
const file_path = path.join(folder_path, name);
|
const file_path = path.join(folder_path, name);
|
||||||
|
|
||||||
// Create directory if it doesn't exist
|
// Create directory if it doesn't exist
|
||||||
|
|||||||
Reference in New Issue
Block a user