update
This commit is contained in:
@ -12,7 +12,7 @@ import { ServiceClassModel } from "../model/service_class";
|
|||||||
import { OrmHelper } from "../helpers/orm";
|
import { OrmHelper } from "../helpers/orm";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import fileUpload from "express-fileupload";
|
import fileUpload from "express-fileupload";
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from "uuid";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { Brackets } from "typeorm";
|
import { Brackets } from "typeorm";
|
||||||
@ -50,9 +50,21 @@ export class RoomController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let param: Paging = await schema.validateAsync(req.query);
|
let param: Paging = await schema.validateAsync(req.query);
|
||||||
let filter = JSON.parse(param.filter);
|
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
||||||
|
const filterAny = filter.any && filter.any !== "" ? String(filter.any) : "";
|
||||||
|
let filterObj = { ...filter } as any;
|
||||||
|
delete filterObj.any;
|
||||||
|
|
||||||
var query = await RoomModel.list(filter);
|
var query = await RoomModel.list(filterObj);
|
||||||
|
|
||||||
|
if (filterAny !== "") {
|
||||||
|
const anyVal = filterAny.includes("%") ? filterAny : `%${filterAny}%`;
|
||||||
|
query.andWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.where("Room.code ILIKE :any", { any: anyVal }).orWhere("Room.room ILIKE :any", { any: anyVal });
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const offset = (param.page - 1) * param.limit;
|
const offset = (param.page - 1) * param.limit;
|
||||||
const res_count = query;
|
const res_count = query;
|
||||||
@ -75,9 +87,7 @@ export class RoomController {
|
|||||||
const list_data = await res_list.getMany();
|
const list_data = await res_list.getMany();
|
||||||
const mapped_data = list_data.map((item: any) => ({
|
const mapped_data = list_data.map((item: any) => ({
|
||||||
...item,
|
...item,
|
||||||
picture: item.picture
|
picture: item.picture ? photoBaseUrl + item.picture : null,
|
||||||
? photoBaseUrl + item.picture
|
|
||||||
: null
|
|
||||||
}));
|
}));
|
||||||
const count_data = CommonHelper.countObject(list_data);
|
const count_data = CommonHelper.countObject(list_data);
|
||||||
|
|
||||||
@ -109,12 +119,7 @@ export class RoomController {
|
|||||||
|
|
||||||
const query = await RoomModel.list();
|
const query = await RoomModel.list();
|
||||||
|
|
||||||
query
|
query.select(["Room.id", "Room.room"]).orderBy("Room.room", "ASC");
|
||||||
.select([
|
|
||||||
"Room.id",
|
|
||||||
"Room.room",
|
|
||||||
])
|
|
||||||
.orderBy("Room.room", "ASC");
|
|
||||||
|
|
||||||
// ✅ optional filter by departmentId
|
// ✅ optional filter by departmentId
|
||||||
if (param.id) {
|
if (param.id) {
|
||||||
@ -127,26 +132,12 @@ export class RoomController {
|
|||||||
const list_data = await query.getMany();
|
const list_data = await query.getMany();
|
||||||
const count_data = CommonHelper.countObject(list_data);
|
const count_data = CommonHelper.countObject(list_data);
|
||||||
|
|
||||||
return ReturnHelper.successResponselist(
|
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, 1, total_count_data, list_data);
|
||||||
res,
|
|
||||||
200,
|
|
||||||
Language.lang.success_view,
|
|
||||||
count_data,
|
|
||||||
1,
|
|
||||||
total_count_data,
|
|
||||||
list_data
|
|
||||||
);
|
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
const err = e as Error;
|
const err = e as Error;
|
||||||
|
|
||||||
return ReturnHelper.errorResponse(
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message);
|
||||||
res,
|
|
||||||
400,
|
|
||||||
401,
|
|
||||||
Language.lang.failed_view,
|
|
||||||
err.message
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,8 +208,7 @@ export class RoomController {
|
|||||||
id: Joi.string().uuid().required().label("Room Id"),
|
id: Joi.string().uuid().required().label("Room Id"),
|
||||||
});
|
});
|
||||||
let param: any = await schema.validateAsync(req.params);
|
let param: any = await schema.validateAsync(req.params);
|
||||||
let room = await RoomModel.list({ "Room.id": param.id })
|
let room = await RoomModel.list({ "Room.id": param.id }).then((q) => q.leftJoinAndSelect("Room.department", "department").leftJoinAndSelect("Room.serviceclass", "serviceclass").getOne());
|
||||||
.then((q) => q.leftJoinAndSelect("Room.department", "department").leftJoinAndSelect("Room.serviceclass", "serviceclass").getOne());
|
|
||||||
if (!room) throw { message: "Room Not Found" };
|
if (!room) throw { message: "Room Not Found" };
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, room);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, room);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
@ -399,7 +389,7 @@ export class RoomController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate file type
|
// Validate file type
|
||||||
const allowedMimes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp'];
|
const allowedMimes = ["image/jpeg", "image/jpg", "image/png", "image/webp"];
|
||||||
if (!allowedMimes.includes(file.mimetype)) {
|
if (!allowedMimes.includes(file.mimetype)) {
|
||||||
return ReturnHelper.errorResponse(res, 400, 400, Language.lang.failed_insert, "Invalid file type. Only JPG, PNG, and WEBP are allowed");
|
return ReturnHelper.errorResponse(res, 400, 400, Language.lang.failed_insert, "Invalid file type. Only JPG, PNG, and WEBP are allowed");
|
||||||
}
|
}
|
||||||
@ -410,8 +400,8 @@ export class RoomController {
|
|||||||
// 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(".");
|
||||||
const name = uuidv4() + '.' + ext[ext.length - 1];
|
const name = uuidv4() + "." + ext[ext.length - 1];
|
||||||
|
|
||||||
const result: { file: string } = {
|
const result: { file: string } = {
|
||||||
// url: "",
|
// url: "",
|
||||||
@ -422,7 +412,7 @@ export class RoomController {
|
|||||||
// md5: file.md5
|
// md5: file.md5
|
||||||
};
|
};
|
||||||
|
|
||||||
const folder_path = 'uploads/room-picture/';
|
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
|
||||||
@ -440,14 +430,13 @@ export class RoomController {
|
|||||||
log.info(`File uploaded successfully: ${file_path}`);
|
log.info(`File uploaded successfully: ${file_path}`);
|
||||||
|
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_insert, result);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_insert, result);
|
||||||
|
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
// Proper error logging to avoid tslog serialization issues
|
// Proper error logging to avoid tslog serialization issues
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
log.error("File upload failed:", {
|
log.error("File upload failed:", {
|
||||||
message: e.message,
|
message: e.message,
|
||||||
stack: e.stack,
|
stack: e.stack,
|
||||||
name: e.name
|
name: e.name,
|
||||||
});
|
});
|
||||||
return ReturnHelper.errorResponse(res, 500, 500, Language.lang.failed_insert, e.message);
|
return ReturnHelper.errorResponse(res, 500, 500, Language.lang.failed_insert, e.message);
|
||||||
} else {
|
} else {
|
||||||
@ -466,7 +455,7 @@ export class RoomController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
file_name: Joi.string().required().label('File Name'),
|
file_name: Joi.string().required().label("File Name"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const param: { file_name: string } = await schema.validateAsync(req.body);
|
const param: { file_name: string } = await schema.validateAsync(req.body);
|
||||||
@ -477,7 +466,7 @@ export class RoomController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// const env = process.env.NODE_ENV + '/'
|
// const env = process.env.NODE_ENV + '/'
|
||||||
const fixedPath = 'uploads/room-picture/';
|
const fixedPath = "uploads/room-picture/";
|
||||||
const file_path = fixedPath + param.file_name;
|
const file_path = fixedPath + param.file_name;
|
||||||
|
|
||||||
// Check if file exists
|
// Check if file exists
|
||||||
@ -504,18 +493,18 @@ export class RoomController {
|
|||||||
#swagger.description = 'Get all room pictures from uploads/room-picture/template directory".'
|
#swagger.description = 'Get all room pictures from uploads/room-picture/template directory".'
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const filePath = 'uploads/room-picture/template/';
|
const filePath = "uploads/room-picture/template/";
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, []);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = fs.readdirSync(filePath)
|
const files = fs.readdirSync(filePath);
|
||||||
|
|
||||||
const photoBaseUrl = "https://his.shiblysolution.id/service-master-data/uploads/room-picture/template/";
|
const photoBaseUrl = "https://his.shiblysolution.id/service-master-data/uploads/room-picture/template/";
|
||||||
const filesWithUrl = files.map((filename, index) => ({
|
const filesWithUrl = files.map((filename, index) => ({
|
||||||
id: index,
|
id: index,
|
||||||
name: `template/${filename}`,
|
name: `template/${filename}`,
|
||||||
url: photoBaseUrl + filename
|
url: photoBaseUrl + filename,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, filesWithUrl);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, filesWithUrl);
|
||||||
|
|||||||
@ -125,8 +125,10 @@ export class RoomToPharmacyController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter tambahan jika ada
|
// Filter tambahan jika ada
|
||||||
if (filter.room) {
|
const roomNameFilter = filter["room.name"] ?? filter.room;
|
||||||
roomQuery.andWhere("room.room ILIKE :room", { room: `%${filter.room}%` });
|
if (roomNameFilter !== undefined && roomNameFilter !== "") {
|
||||||
|
const roomVal = String(roomNameFilter);
|
||||||
|
roomQuery.andWhere("room.room ILIKE :room", { room: roomVal.includes("%") ? roomVal : `%${roomVal}%` });
|
||||||
}
|
}
|
||||||
if (filter.status) {
|
if (filter.status) {
|
||||||
roomQuery.andWhere("room.status = :status", { status: filter.status });
|
roomQuery.andWhere("room.status = :status", { status: filter.status });
|
||||||
|
|||||||
@ -52,8 +52,19 @@ export class ScheduleController {
|
|||||||
order_direction: "asc" | "desc";
|
order_direction: "asc" | "desc";
|
||||||
} = await schema.validateAsync(req.query);
|
} = await schema.validateAsync(req.query);
|
||||||
|
|
||||||
const filterObj = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
const filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
||||||
|
const filterAny = filter.any && filter.any !== "" ? String(filter.any) : "";
|
||||||
|
const filterObj = { ...filter } as any;
|
||||||
|
delete filterObj.any;
|
||||||
|
|
||||||
const query = await ScheduleModel.listSeries(filterObj);
|
const query = await ScheduleModel.listSeries(filterObj);
|
||||||
|
if (filterAny !== "") {
|
||||||
|
const anyVal = filterAny.includes("%") ? filterAny : `%${filterAny}%`;
|
||||||
|
query.andWhere(
|
||||||
|
"(ScheduleSeries.title ILIKE :any OR Room.room ILIKE :any OR Room.code ILIKE :any OR Doctor.name ILIKE :any OR Doctor.username ILIKE :any)",
|
||||||
|
{ any: anyVal }
|
||||||
|
);
|
||||||
|
}
|
||||||
const orderDirection = param.order_direction.toUpperCase() as "ASC" | "DESC";
|
const orderDirection = param.order_direction.toUpperCase() as "ASC" | "DESC";
|
||||||
|
|
||||||
const offset = (param.page - 1) * param.limit;
|
const offset = (param.page - 1) * param.limit;
|
||||||
|
|||||||
Reference in New Issue
Block a user