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