Merge branch 'main' of https://git.shiblysolution.id/SAUDE-TL/service-master-data
This commit is contained in:
@ -79,28 +79,28 @@ export class PharmacyInfoController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async detail(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
static async detail(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['Pharmacy - PharmacyInfo']
|
#swagger.tags = ['Pharmacy - PharmacyInfo']
|
||||||
#swagger.security = [{ "bearerAuth": [] }]
|
#swagger.security = [{ "bearerAuth": [] }]
|
||||||
#swagger.parameters['id'] = { description: '', in: 'path', type: 'string' }
|
#swagger.parameters['id'] = { description: '', in: 'path', type: 'string' }
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
id: Joi.string().uuid().required().label("Pharmacy Info Id"),
|
id: Joi.string().uuid().required().label("Pharmacy Info Id"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let param: any = await schema.validateAsync(req.params);
|
let param: any = await schema.validateAsync(req.params);
|
||||||
|
|
||||||
let data = await PharmacyInfoModel.list({ "id": param.id }).then((q) => q.getOne());
|
let data = await PharmacyInfoModel.list({ "id": param.id }).then((q) => q.getOne());
|
||||||
if (!data) throw { message: "Pharmacy Info Not Found" };
|
if (!data) throw { message: "Pharmacy Info Not Found" };
|
||||||
|
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, data);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, 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(res, 400, 401, Language.lang.failed_not_found, err.message);
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_not_found, err.message);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static async export(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
static async export(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
/*
|
/*
|
||||||
@ -144,7 +144,7 @@ export class PharmacyInfoController {
|
|||||||
|
|
||||||
var query = await PharmacyInfoModel.list(filter);
|
var query = await PharmacyInfoModel.list(filter);
|
||||||
const data = await query.getMany();
|
const data = await query.getMany();
|
||||||
|
|
||||||
const filename = "pharmacy_info.csv";
|
const filename = "pharmacy_info.csv";
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'text/csv');
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
@ -250,6 +250,11 @@ export class PharmacyInfoController {
|
|||||||
.uuid()
|
.uuid()
|
||||||
.required()
|
.required()
|
||||||
.label('Default Room'),
|
.label('Default Room'),
|
||||||
|
|
||||||
|
province: Joi.string().allow("").optional().label("Province Code"),
|
||||||
|
city: Joi.string().allow("").optional().label("City Code"),
|
||||||
|
subdistrict: Joi.string().allow("").optional().label("Subdistrict Code"),
|
||||||
|
ward: Joi.string().allow("").optional().label("Ward Code"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const param: any = await schema.validateAsync(req.body);
|
const param: any = await schema.validateAsync(req.body);
|
||||||
@ -264,7 +269,11 @@ export class PharmacyInfoController {
|
|||||||
data.phone = param.phone
|
data.phone = param.phone
|
||||||
data.default_room = param.default_room_id
|
data.default_room = param.default_room_id
|
||||||
data.logo = param.logo
|
data.logo = param.logo
|
||||||
data.created_by = req.auth.data.name;
|
data.province = param.province
|
||||||
|
data.city = param.city
|
||||||
|
data.subdistrict = param.subdistrict
|
||||||
|
data.ward = param.ward
|
||||||
|
data.created_by = req.auth?.data.name;
|
||||||
|
|
||||||
await OrmHelper.DB.manager.save(data);
|
await OrmHelper.DB.manager.save(data);
|
||||||
|
|
||||||
@ -369,7 +378,11 @@ export class PharmacyInfoController {
|
|||||||
data.phone = param.phone
|
data.phone = param.phone
|
||||||
data.default_room = param.default_room_id
|
data.default_room = param.default_room_id
|
||||||
data.logo = param.logo
|
data.logo = param.logo
|
||||||
data.updated_by = req.auth.data.name;
|
data.province = param.province
|
||||||
|
data.city = param.city
|
||||||
|
data.subdistrict = param.subdistrict
|
||||||
|
data.ward = param.ward
|
||||||
|
data.updated_by = req.auth?.data.name;
|
||||||
|
|
||||||
await repo.save(data);
|
await repo.save(data);
|
||||||
|
|
||||||
@ -416,7 +429,7 @@ export class PharmacyInfoController {
|
|||||||
|
|
||||||
const existData = await repo.findOne({ where: { id: param.id } });
|
const existData = await repo.findOne({ where: { id: param.id } });
|
||||||
if (existData && !param.hard) {
|
if (existData && !param.hard) {
|
||||||
existData.deleted_by = req.auth.data.name;
|
existData.deleted_by = req.auth?.data.name;
|
||||||
await OrmHelper.DB.manager.save(existData);
|
await OrmHelper.DB.manager.save(existData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,33 +638,33 @@ export class PharmacyInfoController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async view(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
static async view(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['Pharmacy - PharmacyInfo']
|
#swagger.tags = ['Pharmacy - PharmacyInfo']
|
||||||
#swagger.security = [{ "bearerAuth": [] }]
|
#swagger.security = [{ "bearerAuth": [] }]
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const data = await OrmHelper.DB
|
const data = await OrmHelper.DB
|
||||||
.getRepository(PharmacyInfo)
|
.getRepository(PharmacyInfo)
|
||||||
.findOne({
|
.findOne({
|
||||||
where: {}
|
where: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!data) return ReturnHelper.errorResponse(res, 404, 404, Language.lang.failed_view, "data not found");
|
if (!data) return ReturnHelper.errorResponse(res, 404, 404, Language.lang.failed_view, "data not found");
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
address: data.address,
|
address: data.address,
|
||||||
phone: data.phone,
|
phone: data.phone,
|
||||||
logo: 'http://his.shiblysolution.id:3011/service-master-data/uploads/hospital-logo/' + data.logo
|
logo: 'http://his.shiblysolution.id:3011/service-master-data/uploads/hospital-logo/' + data.logo
|
||||||
};
|
};
|
||||||
|
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, result);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, result);
|
||||||
|
|
||||||
} 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(res,400,401,Language.lang.failed_view,err.message);
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
164
src/controllers/region.ts
Normal file
164
src/controllers/region.ts
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
import { Response, NextFunction, Application } from "express";
|
||||||
|
import { Request } from "express-jwt";
|
||||||
|
import { ReturnHelper } from "../helpers/express/return";
|
||||||
|
import { OrmHelper } from "../helpers/orm";
|
||||||
|
import Joi from "joi";
|
||||||
|
import { ILogObj, Logger } from "tslog";
|
||||||
|
import { Language } from "../langs/lang";
|
||||||
|
import { Paging } from "entity";
|
||||||
|
import CommonHelper from "../helpers/common";
|
||||||
|
import * as fastcsv from 'fast-csv';
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import { Province, City, Subdistrict, Ward } from "entity";
|
||||||
|
|
||||||
|
const log: Logger<ILogObj> = new Logger({ name: '[RegionController]', type: 'pretty' });
|
||||||
|
|
||||||
|
export class RegionController {
|
||||||
|
static async province(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['Region']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
const repo = OrmHelper.DB.getRepository(Province);
|
||||||
|
|
||||||
|
const res_count = repo.createQueryBuilder("province");
|
||||||
|
const res_list = repo.createQueryBuilder("province");
|
||||||
|
|
||||||
|
const current_page = 1;
|
||||||
|
const total_count_data = await res_count.getCount();
|
||||||
|
const list_data = await res_list.getMany();
|
||||||
|
const count_data = CommonHelper.countObject(list_data);
|
||||||
|
|
||||||
|
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async city(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['Region']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
#swagger.parameters['province_code'] = {
|
||||||
|
in: 'path',
|
||||||
|
description: 'Province Code.',
|
||||||
|
required: true,
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { province_code } = req.params;
|
||||||
|
|
||||||
|
if (!/^\d{2}$/.test(province_code)) {
|
||||||
|
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, 0, 1, 0, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
const repo = OrmHelper.DB.getRepository(City);
|
||||||
|
const res_count = repo.createQueryBuilder("city")
|
||||||
|
.where("city.code LIKE :province_code", { province_code: `${province_code}%` });
|
||||||
|
const res_list = repo.createQueryBuilder("city")
|
||||||
|
.where("city.code LIKE :province_code", { province_code: `${province_code}%` });
|
||||||
|
|
||||||
|
const current_page = 1;
|
||||||
|
const total_count_data = await res_count.getCount();
|
||||||
|
const list_data = await res_list.getMany();
|
||||||
|
const count_data = CommonHelper.countObject(list_data);
|
||||||
|
|
||||||
|
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async subdistrict(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['Region']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
#swagger.parameters['city_code'] = {
|
||||||
|
in: 'path',
|
||||||
|
description: 'City Code.',
|
||||||
|
required: true,
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { city_code } = req.params;
|
||||||
|
|
||||||
|
if (!/^\d{2}\.\d{2}$/.test(city_code)) {
|
||||||
|
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, 0, 1, 0, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
const repo = OrmHelper.DB.getRepository(Subdistrict);
|
||||||
|
const res_count = repo.createQueryBuilder("subdistrict")
|
||||||
|
.where("subdistrict.code LIKE :city_code", { city_code: `${city_code}%` });
|
||||||
|
const res_list = repo.createQueryBuilder("subdistrict")
|
||||||
|
.where("subdistrict.code LIKE :city_code", { city_code: `${city_code}%` });
|
||||||
|
|
||||||
|
const current_page = 1;
|
||||||
|
const total_count_data = await res_count.getCount();
|
||||||
|
const list_data = await res_list.getMany();
|
||||||
|
const count_data = CommonHelper.countObject(list_data);
|
||||||
|
|
||||||
|
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async ward(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['Region']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
#swagger.parameters['subdistric_code'] = {
|
||||||
|
in: 'path',
|
||||||
|
description: 'Subdistric Code.',
|
||||||
|
required: true,
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { subdistric_code } = req.params;
|
||||||
|
|
||||||
|
if (!/^\d{2}\.\d{2}\.\d{2}$/.test(subdistric_code)) {
|
||||||
|
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, 0, 1, 0, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
const repo = OrmHelper.DB.getRepository(Ward);
|
||||||
|
const res_count = repo.createQueryBuilder("ward")
|
||||||
|
.where("ward.code LIKE :subdistric_code", { subdistric_code: `${subdistric_code}%` });
|
||||||
|
const res_list = repo.createQueryBuilder("ward")
|
||||||
|
.where("ward.code LIKE :subdistric_code", { subdistric_code: `${subdistric_code}%` });
|
||||||
|
|
||||||
|
const current_page = 1;
|
||||||
|
const total_count_data = await res_count.getCount();
|
||||||
|
const list_data = await res_list.getMany();
|
||||||
|
const count_data = CommonHelper.countObject(list_data);
|
||||||
|
|
||||||
|
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -36,31 +36,99 @@ export class RoomToPharmacyController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let param: Paging = await schema.validateAsync(req.query);
|
let param: Paging = await schema.validateAsync(req.query);
|
||||||
|
|
||||||
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
||||||
|
|
||||||
var query = await RoomToPharmacyModel.list(filter);
|
|
||||||
|
|
||||||
const offset = (param.page - 1) * param.limit;
|
const offset = (param.page - 1) * param.limit;
|
||||||
let limit = param.limit;
|
const limit = param.limit;
|
||||||
|
|
||||||
const res_count = query;
|
const roomQuery = OrmHelper.DB.getRepository(Room)
|
||||||
const res_list = query
|
.createQueryBuilder("room")
|
||||||
.orderBy("room_to_pharmacy." + param.order_field, param.order_direction)
|
.leftJoinAndSelect("room.department", "department")
|
||||||
.offset(offset)
|
.leftJoinAndMapMany(
|
||||||
.limit(limit);
|
"room.roomToPharmacies",
|
||||||
|
RoomToPharmacy,
|
||||||
|
"room_to_pharmacy",
|
||||||
|
"room_to_pharmacy.room_id = room.id"
|
||||||
|
)
|
||||||
|
.leftJoinAndMapOne(
|
||||||
|
"room_to_pharmacy.pharmacy_room",
|
||||||
|
Room,
|
||||||
|
"pharmacy_room",
|
||||||
|
"pharmacy_room.id = room_to_pharmacy.pharmacy_room_id"
|
||||||
|
)
|
||||||
|
.where("department.id IN (:...departmentIds)", {
|
||||||
|
departmentIds: [
|
||||||
|
'42bc42a7-e2a7-4f95-a788-9d9e51a51a20',
|
||||||
|
'3fc39ff1-b4bc-4276-92ef-def7ca9432fb',
|
||||||
|
'a0d2ef11-6927-4e5c-8628-6acf26351071',
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.orderBy("room." + param.order_field, param.order_direction as "ASC" | "DESC");
|
||||||
|
|
||||||
if (param.with_deleted) {
|
if (param.with_deleted) {
|
||||||
res_count.withDeleted();
|
roomQuery.withDeleted();
|
||||||
res_list.withDeleted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const current_page = param.page;
|
// Filter tambahan jika ada
|
||||||
const total_count_data = await res_count.getCount();
|
if (filter.room) {
|
||||||
const list_data = await res_list.getMany();
|
roomQuery.andWhere("room.room ILIKE :room", { room: `%${filter.room}%` });
|
||||||
const count_data = CommonHelper.countObject(list_data);
|
}
|
||||||
|
if (filter.status) {
|
||||||
|
roomQuery.andWhere("room.status = :status", { status: filter.status });
|
||||||
|
}
|
||||||
|
|
||||||
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, list_data);
|
const total_count_data = await roomQuery.clone().getCount();
|
||||||
|
|
||||||
|
const rooms = await roomQuery
|
||||||
|
.offset(offset)
|
||||||
|
.limit(limit)
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
// Transform: { room_name: { pharmacy_room_1: {}, pharmacy_room_2: {} } }
|
||||||
|
const list_data_return = rooms.map((room: any) => {
|
||||||
|
const roomToPharmacies: any[] = room.roomToPharmacies ?? [];
|
||||||
|
|
||||||
|
const pharmacyRooms: Record<string, any> = {};
|
||||||
|
roomToPharmacies.forEach((rtp: any, index: number) => {
|
||||||
|
const pharmacy: Room | null = rtp.pharmacy_room ?? null;
|
||||||
|
pharmacyRooms[`pharmacy_room_${index + 1}`] = pharmacy ? {
|
||||||
|
id: pharmacy.id,
|
||||||
|
room: pharmacy.room,
|
||||||
|
code: pharmacy.code,
|
||||||
|
description: pharmacy.description ?? null,
|
||||||
|
status: pharmacy.status,
|
||||||
|
} : null;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
rooms: {
|
||||||
|
id: room.id,
|
||||||
|
room: room.room,
|
||||||
|
code: room.code,
|
||||||
|
description: room.description ?? null,
|
||||||
|
status: room.status,
|
||||||
|
department: room.department ? {
|
||||||
|
id: room.department.id,
|
||||||
|
name: room.department.name,
|
||||||
|
} : null,
|
||||||
|
pharmacy_rooms: Object.keys(pharmacyRooms).length > 0
|
||||||
|
? pharmacyRooms
|
||||||
|
: null,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const count_data = CommonHelper.countObject(list_data_return);
|
||||||
|
|
||||||
|
return ReturnHelper.successResponselist(
|
||||||
|
res,
|
||||||
|
200,
|
||||||
|
Language.lang.success_view,
|
||||||
|
count_data,
|
||||||
|
param.page,
|
||||||
|
total_count_data,
|
||||||
|
list_data_return
|
||||||
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
const err = e as Error;
|
const err = e as Error;
|
||||||
@ -110,7 +178,7 @@ export class RoomToPharmacyController {
|
|||||||
|
|
||||||
var query = await RoomToPharmacyModel.list(filter);
|
var query = await RoomToPharmacyModel.list(filter);
|
||||||
const data = await query.getMany();
|
const data = await query.getMany();
|
||||||
|
|
||||||
const filename = "room_to_pharmacy.csv";
|
const filename = "room_to_pharmacy.csv";
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'text/csv');
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
@ -173,15 +241,15 @@ export class RoomToPharmacyController {
|
|||||||
try {
|
try {
|
||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
pharmacy_room_id: Joi.string()
|
pharmacy_room_id: Joi.string()
|
||||||
.uuid()
|
.uuid()
|
||||||
.required()
|
.required()
|
||||||
.label("Pharmacy Room ID"),
|
.label("Pharmacy Room ID"),
|
||||||
|
|
||||||
room_id: Joi.string()
|
room_id: Joi.string()
|
||||||
.uuid()
|
.uuid()
|
||||||
.required()
|
.required()
|
||||||
.label("Room ID"),
|
.label("Room ID"),
|
||||||
|
|
||||||
// room_ids: Joi.array()
|
// room_ids: Joi.array()
|
||||||
// .items(Joi.string().uuid().required())
|
// .items(Joi.string().uuid().required())
|
||||||
// .min(1)
|
// .min(1)
|
||||||
@ -194,7 +262,7 @@ export class RoomToPharmacyController {
|
|||||||
const data = new RoomToPharmacy()
|
const data = new RoomToPharmacy()
|
||||||
data.pharmacy_room = param.pharmacy_room_id;
|
data.pharmacy_room = param.pharmacy_room_id;
|
||||||
data.room = param.room_id;
|
data.room = param.room_id;
|
||||||
data.created_by = req.auth.data.name;
|
data.created_by = req.auth?.data.name;
|
||||||
|
|
||||||
await OrmHelper.DB.manager.save(data);
|
await OrmHelper.DB.manager.save(data);
|
||||||
|
|
||||||
@ -229,7 +297,7 @@ export class RoomToPharmacyController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async update(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
static async update(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['RoomToPharmacy']
|
#swagger.tags = ['RoomToPharmacy']
|
||||||
#swagger.security = [{
|
#swagger.security = [{
|
||||||
@ -310,26 +378,43 @@ export class RoomToPharmacyController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async detail(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
static async detail(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['RoomToPharmacy']
|
#swagger.tags = ['RoomToPharmacy']
|
||||||
#swagger.security = [{ "bearerAuth": [] }]
|
#swagger.security = [{ "bearerAuth": [] }]
|
||||||
#swagger.parameters['id'] = { description: '', in: 'path', type: 'string' }
|
#swagger.parameters['id'] = { description: '', in: 'path', type: 'string' }
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
id: Joi.string().uuid().required().label("RoomToPharmacy 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 data = await RoomToPharmacyModel.list({ "id": param.id }).then((q) => q.getOne());
|
let data = await OrmHelper.DB.getRepository(Room)
|
||||||
if (!data) throw { message: "RoomToPharmacy Not Found" };
|
.createQueryBuilder("room")
|
||||||
|
.leftJoinAndSelect("room.department", "department")
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, data);
|
.leftJoinAndMapMany(
|
||||||
} catch (e: unknown) {
|
"room.roomToPharmacies",
|
||||||
log.error(e);
|
RoomToPharmacy,
|
||||||
const err = e as Error;
|
"room_to_pharmacy",
|
||||||
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_not_found, err.message);
|
"room_to_pharmacy.room_id = room.id"
|
||||||
}
|
)
|
||||||
}
|
.leftJoinAndMapOne(
|
||||||
|
"room_to_pharmacy.pharmacy_room",
|
||||||
|
Room,
|
||||||
|
"pharmacy_room",
|
||||||
|
"pharmacy_room.id = room_to_pharmacy.pharmacy_room_id"
|
||||||
|
)
|
||||||
|
.where("room.id = :id", { id: param.id })
|
||||||
|
.getOne();
|
||||||
|
|
||||||
|
if (!data) throw { message: "RoomToPharmacy Not Found" };
|
||||||
|
|
||||||
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, data);
|
||||||
|
} catch (e: unknown) {
|
||||||
|
log.error(e);
|
||||||
|
const err = e as Error;
|
||||||
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_not_found, err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -39,28 +39,85 @@ export class UserToRoomController {
|
|||||||
|
|
||||||
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {};
|
||||||
|
|
||||||
var query = await UserToRoomModel.list(filter);
|
|
||||||
|
|
||||||
const offset = (param.page - 1) * param.limit;
|
const offset = (param.page - 1) * param.limit;
|
||||||
let limit = param.limit;
|
const limit = param.limit;
|
||||||
|
|
||||||
const res_count = query;
|
// Query dari User sebagai root, leftJoin ke UserToRoom → Room
|
||||||
const res_list = query
|
const userQuery = OrmHelper.DB.getRepository(User)
|
||||||
.orderBy("user_to_room." + param.order_field, param.order_direction)
|
.createQueryBuilder("user")
|
||||||
.offset(offset)
|
.leftJoinAndSelect("user.roles", "roles")
|
||||||
.limit(limit);
|
.leftJoinAndMapMany(
|
||||||
|
"user.userToRooms",
|
||||||
|
UserToRoom,
|
||||||
|
"user_to_room",
|
||||||
|
"user_to_room.user = user.id"
|
||||||
|
)
|
||||||
|
.leftJoinAndMapOne(
|
||||||
|
"user_to_room.roomData",
|
||||||
|
Room,
|
||||||
|
"room",
|
||||||
|
"room.id = user_to_room.room"
|
||||||
|
)
|
||||||
|
.orderBy("user." + param.order_field, param.order_direction as "ASC" | "DESC");
|
||||||
|
|
||||||
if (param.with_deleted) {
|
if (param.with_deleted) {
|
||||||
res_count.withDeleted();
|
userQuery.withDeleted();
|
||||||
res_list.withDeleted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const current_page = param.page;
|
// Filter jika ada
|
||||||
const total_count_data = await res_count.getCount();
|
if (filter.name) {
|
||||||
const list_data = await res_list.getMany();
|
userQuery.andWhere("user.name ILIKE :name", { name: `%${filter.name}%` });
|
||||||
const count_data = CommonHelper.countObject(list_data);
|
}
|
||||||
|
if (filter.status) {
|
||||||
|
userQuery.andWhere("user.status = :status", { status: filter.status });
|
||||||
|
}
|
||||||
|
|
||||||
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, list_data);
|
const total_count_data = await userQuery.clone().getCount();
|
||||||
|
|
||||||
|
const users = await userQuery
|
||||||
|
.offset(offset)
|
||||||
|
.limit(limit)
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
// Transform data
|
||||||
|
const list_data_return = users.map((user: any) => {
|
||||||
|
const userToRooms: any[] = user.userToRooms ?? [];
|
||||||
|
|
||||||
|
const rooms: Record<string, any> = {};
|
||||||
|
userToRooms.forEach((utr: any, index: number) => {
|
||||||
|
const room = utr.roomData ?? null;
|
||||||
|
rooms[`room_${index + 1}`] = room ? {
|
||||||
|
id: room.id,
|
||||||
|
room: room.room,
|
||||||
|
code: room.code,
|
||||||
|
} : null;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: user.id,
|
||||||
|
name: user.name,
|
||||||
|
username: user.username,
|
||||||
|
email: user.email,
|
||||||
|
status: user.status,
|
||||||
|
roles: user.roles ? user.roles.map((role: any) => ({
|
||||||
|
id: role.id,
|
||||||
|
name: role.name,
|
||||||
|
})) : [],
|
||||||
|
rooms: Object.keys(rooms).length > 0 ? rooms : null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const count_data = CommonHelper.countObject(list_data_return);
|
||||||
|
|
||||||
|
return ReturnHelper.successResponselist(
|
||||||
|
res,
|
||||||
|
200,
|
||||||
|
Language.lang.success_view,
|
||||||
|
count_data,
|
||||||
|
param.page,
|
||||||
|
total_count_data,
|
||||||
|
list_data_return
|
||||||
|
);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
const err = e as Error;
|
const err = e as Error;
|
||||||
@ -110,7 +167,7 @@ export class UserToRoomController {
|
|||||||
|
|
||||||
var query = await UserToRoomModel.list(filter);
|
var query = await UserToRoomModel.list(filter);
|
||||||
const data = await query.getMany();
|
const data = await query.getMany();
|
||||||
|
|
||||||
const filename = "user_to_room.csv";
|
const filename = "user_to_room.csv";
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'text/csv');
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
@ -173,15 +230,15 @@ export class UserToRoomController {
|
|||||||
try {
|
try {
|
||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
user_id: Joi.string()
|
user_id: Joi.string()
|
||||||
.uuid()
|
.uuid()
|
||||||
.required()
|
.required()
|
||||||
.label("User ID"),
|
.label("User ID"),
|
||||||
|
|
||||||
room_id: Joi.string()
|
room_id: Joi.string()
|
||||||
.uuid()
|
.uuid()
|
||||||
.required()
|
.required()
|
||||||
.label("Room ID"),
|
.label("Room ID"),
|
||||||
|
|
||||||
// room_ids: Joi.array()
|
// room_ids: Joi.array()
|
||||||
// .items(Joi.string().uuid().required())
|
// .items(Joi.string().uuid().required())
|
||||||
// .min(1)
|
// .min(1)
|
||||||
@ -205,7 +262,7 @@ export class UserToRoomController {
|
|||||||
const data = new UserToRoom()
|
const data = new UserToRoom()
|
||||||
data.user = param.user_id;
|
data.user = param.user_id;
|
||||||
data.room = param.room_id;
|
data.room = param.room_id;
|
||||||
data.created_by = req.auth.data.name;
|
data.created_by = req.auth?.data.name;
|
||||||
|
|
||||||
await OrmHelper.DB.manager.save(data);
|
await OrmHelper.DB.manager.save(data);
|
||||||
|
|
||||||
@ -234,117 +291,117 @@ export class UserToRoomController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async update(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
static async update(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['UserToRoom']
|
#swagger.tags = ['UserToRoom']
|
||||||
#swagger.security = [{
|
#swagger.security = [{
|
||||||
"bearerAuth": []
|
"bearerAuth": []
|
||||||
}]
|
}]
|
||||||
#swagger.parameters['user_id'] = {
|
#swagger.parameters['user_id'] = {
|
||||||
in: 'path',
|
in: 'path',
|
||||||
description: 'User ID.',
|
description: 'User ID.',
|
||||||
required: true,
|
required: true,
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
|
|
||||||
#swagger.requestBody = {
|
#swagger.requestBody = {
|
||||||
required: true,
|
required: true,
|
||||||
content: {
|
content: {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
schema: {
|
schema: {
|
||||||
$ref: "#/components/schemas/user_to_room_update"
|
$ref: "#/components/schemas/user_to_room_update"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
*/
|
||||||
try {
|
|
||||||
const schema = Joi.object().keys({
|
try {
|
||||||
user_id: Joi.string().uuid().required().label('User ID'),
|
const schema = Joi.object().keys({
|
||||||
room_ids: Joi.array()
|
user_id: Joi.string().uuid().required().label('User ID'),
|
||||||
|
room_ids: Joi.array()
|
||||||
.items(Joi.string().uuid().required())
|
.items(Joi.string().uuid().required())
|
||||||
.min(1)
|
.min(1)
|
||||||
.required()
|
.required()
|
||||||
.label("Factory IDs")
|
.label("Factory IDs")
|
||||||
// room_id: Joi.string().uuid().required().label('Room ID'),
|
// room_id: Joi.string().uuid().required().label('Room ID'),
|
||||||
});
|
});
|
||||||
|
|
||||||
req.body.user_id = req.params['user_id'];
|
|
||||||
|
|
||||||
const param: any = await schema.validateAsync(req.body);
|
|
||||||
|
|
||||||
const userToRoomRepo = OrmHelper.DB.getRepository(UserToRoom);
|
req.body.user_id = req.params['user_id'];
|
||||||
const userRepo = OrmHelper.DB.getRepository(User);
|
|
||||||
const roomRepo = OrmHelper.DB.getRepository(Room);
|
|
||||||
|
|
||||||
await userToRoomRepo
|
const param: any = await schema.validateAsync(req.body);
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(UserToRoom)
|
|
||||||
.where("service_id = :userId", { userId: param.user_id })
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
let relation : UserToRoom;
|
const userToRoomRepo = OrmHelper.DB.getRepository(UserToRoom);
|
||||||
for (const roomId of param.room_ids) {
|
const userRepo = OrmHelper.DB.getRepository(User);
|
||||||
relation = new UserToRoom();
|
const roomRepo = OrmHelper.DB.getRepository(Room);
|
||||||
relation.user = await userRepo.findOneBy({ id: param.user_id });
|
|
||||||
relation.room = await roomRepo.findOneBy({ id: roomId });
|
|
||||||
relation.created_by = req.auth.data.name;
|
|
||||||
|
|
||||||
await userToRoomRepo.save(relation);
|
await userToRoomRepo
|
||||||
}
|
.createQueryBuilder()
|
||||||
|
.delete()
|
||||||
|
.from(UserToRoom)
|
||||||
|
.where("service_id = :userId", { userId: param.user_id })
|
||||||
|
.execute();
|
||||||
|
|
||||||
const data = await userToRoomRepo.createQueryBuilder("user_to_room")
|
let relation: UserToRoom;
|
||||||
|
for (const roomId of param.room_ids) {
|
||||||
|
relation = new UserToRoom();
|
||||||
|
relation.user = await userRepo.findOneBy({ id: param.user_id });
|
||||||
|
relation.room = await roomRepo.findOneBy({ id: roomId });
|
||||||
|
relation.created_by = req.auth.data.name;
|
||||||
|
|
||||||
|
await userToRoomRepo.save(relation);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await userToRoomRepo.createQueryBuilder("user_to_room")
|
||||||
.leftJoinAndSelect("user_to_room.user", "user")
|
.leftJoinAndSelect("user_to_room.user", "user")
|
||||||
.leftJoinAndSelect("user_to_room.room", "room")
|
.leftJoinAndSelect("user_to_room.room", "room")
|
||||||
.where("user_to_room.service_id = :userId", { userId: param.user_id }).getMany();
|
.where("user_to_room.service_id = :userId", { userId: param.user_id }).getMany();
|
||||||
|
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_update, data);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_update, data);
|
||||||
|
|
||||||
// const repo = OrmHelper.DB.getRepository(UserToRoom);
|
// const repo = OrmHelper.DB.getRepository(UserToRoom);
|
||||||
|
|
||||||
// const data = await repo.findOneBy({ id: param.id });
|
// const data = await repo.findOneBy({ id: param.id });
|
||||||
|
|
||||||
// if (data != null) {
|
// if (data != null) {
|
||||||
// data.user = param.user_id;
|
// data.user = param.user_id;
|
||||||
// data.room = param.room_id;
|
// data.room = param.room_id;
|
||||||
// data.updated_by = req.auth.data.name;
|
// data.updated_by = req.auth.data.name;
|
||||||
|
|
||||||
// await repo.save(data);
|
// await repo.save(data);
|
||||||
|
|
||||||
// return ReturnHelper.successResponseAny(res, 200, Language.lang.success_update, data);
|
// return ReturnHelper.successResponseAny(res, 200, Language.lang.success_update, data);
|
||||||
// } else {
|
// } else {
|
||||||
// return ReturnHelper.errorResponse(res, 404, 401, Language.lang.failed_not_found, "");
|
// return ReturnHelper.errorResponse(res, 404, 401, Language.lang.failed_not_found, "");
|
||||||
// }
|
// }
|
||||||
} 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(res, 500, 402, Language.lang.failed_update, err.message);
|
return ReturnHelper.errorResponse(res, 500, 402, Language.lang.failed_update, err.message);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static async detail(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
static async detail(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['UserToRoom']
|
#swagger.tags = ['UserToRoom']
|
||||||
#swagger.security = [{ "bearerAuth": [] }]
|
#swagger.security = [{ "bearerAuth": [] }]
|
||||||
#swagger.parameters['id'] = { description: '', in: 'path', type: 'string' }
|
#swagger.parameters['id'] = { description: '', in: 'path', type: 'string' }
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const schema = Joi.object().keys({
|
const schema = Joi.object().keys({
|
||||||
id: Joi.string().uuid().required().label("UserToRoom Id"),
|
id: Joi.string().uuid().required().label("UserToRoom Id"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let param: any = await schema.validateAsync(req.params);
|
let param: any = await schema.validateAsync(req.params);
|
||||||
|
|
||||||
let data = await UserToRoomModel.list({ "id": param.id }).then((q) => q.getOne());
|
let data = await UserToRoomModel.list({ "id": param.id }).then((q) => q.getOne());
|
||||||
if (!data) throw { message: "UserToRoom Not Found" };
|
if (!data) throw { message: "UserToRoom Not Found" };
|
||||||
|
|
||||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, data);
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_view, 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(res, 400, 401, Language.lang.failed_not_found, err.message);
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_not_found, err.message);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { DataSource } from "typeorm";
|
import { DataSource } from "typeorm";
|
||||||
import { ILogObj, Logger } from 'tslog';
|
import { ILogObj, Logger } from 'tslog';
|
||||||
import { RefferalHospital,RegistrationFee,FareType, RoomStock, Administrativu, Aldeia, District, Menu, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, MeasurementUnit, ReferenceRange, QueueMonitoring, ExaminationDetail, ExaminationType, User, UserRole, HrmsEmployee, HrmsDepartment, HrmsPosition, HrmsShift, HospitalInformation, ItemOrigin, ItemType, ItemTypeDetail, Unit, ItemCategory, ItemStatus, UsageInstructions, UsageTime, ItemClass, ItemClassDetail, GenericName, Factory, Supplier, FactoryToSupplier, ItemMaster, ItemGroup, PharmacyInfo, ItemPrice, SellingPricePercentage, PatientGroup, PatientGuarantor, InitialStock, DoctorItem, DoctorItemPackage, UserToRoom, RoomToPharmacy, PlanningVerificator, ScheduleSeries, ScheduleException, CardType, PaymentMethod } from 'entity'
|
import { Province,City,Subdistrict,Ward, RefferalHospital,RegistrationFee,FareType, RoomStock, Administrativu, Aldeia, District, Menu, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, MeasurementUnit, ReferenceRange, QueueMonitoring, ExaminationDetail, ExaminationType, User, UserRole, HrmsEmployee, HrmsDepartment, HrmsPosition, HrmsShift, HospitalInformation, ItemOrigin, ItemType, ItemTypeDetail, Unit, ItemCategory, ItemStatus, UsageInstructions, UsageTime, ItemClass, ItemClassDetail, GenericName, Factory, Supplier, FactoryToSupplier, ItemMaster, ItemGroup, PharmacyInfo, ItemPrice, SellingPricePercentage, PatientGroup, PatientGuarantor, InitialStock, DoctorItem, DoctorItemPackage, UserToRoom, RoomToPharmacy, PlanningVerificator, ScheduleSeries, ScheduleException, CardType, PaymentMethod } from 'entity'
|
||||||
|
|
||||||
export class OrmHelper {
|
export class OrmHelper {
|
||||||
static DB: DataSource = null
|
static DB: DataSource = null
|
||||||
@ -54,7 +54,7 @@ export class OrmHelper {
|
|||||||
CardType,
|
CardType,
|
||||||
PaymentMethod,
|
PaymentMethod,
|
||||||
RegistrationFee,
|
RegistrationFee,
|
||||||
RefferalHospital
|
RefferalHospital,Province,City,Subdistrict,Ward
|
||||||
],
|
],
|
||||||
subscribers: [],
|
subscribers: [],
|
||||||
migrations: [],
|
migrations: [],
|
||||||
|
|||||||
@ -18,7 +18,11 @@ export class PharmacyInfoModel {
|
|||||||
.leftJoinAndSelect("pharmacy_info.munisipiu", "munisipiu")
|
.leftJoinAndSelect("pharmacy_info.munisipiu", "munisipiu")
|
||||||
.leftJoinAndSelect("pharmacy_info.postu_admin", "postu_admin")
|
.leftJoinAndSelect("pharmacy_info.postu_admin", "postu_admin")
|
||||||
.leftJoinAndSelect("pharmacy_info.suco", "suco")
|
.leftJoinAndSelect("pharmacy_info.suco", "suco")
|
||||||
.leftJoinAndSelect("pharmacy_info.aldeia", "aldeia");
|
.leftJoinAndSelect("pharmacy_info.aldeia", "aldeia")
|
||||||
|
.leftJoinAndSelect("pharmacy_info.province", "province")
|
||||||
|
.leftJoinAndSelect("pharmacy_info.city", "city")
|
||||||
|
.leftJoinAndSelect("pharmacy_info.subdistrict", "subdistrict")
|
||||||
|
.leftJoinAndSelect("pharmacy_info.ward", "ward");
|
||||||
if (whereAttr.length != 0) {
|
if (whereAttr.length != 0) {
|
||||||
query = query.where(whereAttr.join(" and "), whereVal);
|
query = query.where(whereAttr.join(" and "), whereVal);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,21 +1,20 @@
|
|||||||
import { SelectQueryBuilder } from "typeorm";
|
import { SelectQueryBuilder } from "typeorm";
|
||||||
import CommonHelper from "../helpers/common";
|
import CommonHelper from "../helpers/common";
|
||||||
import { OrmHelper } from "../helpers/orm";
|
import { OrmHelper } from "../helpers/orm";
|
||||||
import { RoomToPharmacy } from "entity";
|
import { RoomToPharmacy, Room } from "entity";
|
||||||
|
|
||||||
export class RoomToPharmacyModel {
|
export class RoomToPharmacyModel {
|
||||||
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
|
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
|
||||||
|
|
||||||
const repo = OrmHelper.DB.getRepository(RoomToPharmacy);
|
const repo = OrmHelper.DB.getRepository(RoomToPharmacy);
|
||||||
let whereAttr: string[] = [];
|
let whereAttr: string[] = [];
|
||||||
let whereVal: any = {};
|
let whereVal: any = {};
|
||||||
if (filter && Object.keys(filter).length > 0) {
|
if (filter && Object.keys(filter).length > 0) {
|
||||||
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter, "room_to_pharmacy").whereAttr];
|
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter).whereAttr];
|
||||||
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter, "room_to_pharmacy").whereVal };
|
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter).whereVal };
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = repo.createQueryBuilder("room_to_pharmacy")
|
var query = repo.createQueryBuilder("room_to_pharmacy");
|
||||||
.leftJoinAndSelect("room_to_pharmacy.room", "room")
|
|
||||||
.leftJoinAndSelect("room_to_pharmacy.pharmacy_room", "pharmacy_room");
|
|
||||||
if (whereAttr.length != 0) {
|
if (whereAttr.length != 0) {
|
||||||
query = query.where(whereAttr.join(" and "), whereVal);
|
query = query.where(whereAttr.join(" and "), whereVal);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,6 +63,7 @@ import { FareTypeController } from '../controllers/faretype';
|
|||||||
import { CardTypeController } from '../controllers/card_type';
|
import { CardTypeController } from '../controllers/card_type';
|
||||||
import { PaymentMethodController } from '../controllers/payment-method';
|
import { PaymentMethodController } from '../controllers/payment-method';
|
||||||
import { RegistrationFeeController } from '../controllers/registrationfee';
|
import { RegistrationFeeController } from '../controllers/registrationfee';
|
||||||
|
import { RegionController } from '../controllers/region';
|
||||||
|
|
||||||
export class RoutePrivate {
|
export class RoutePrivate {
|
||||||
static setup(app: express.Application) {
|
static setup(app: express.Application) {
|
||||||
@ -480,9 +481,14 @@ export class RoutePrivate {
|
|||||||
app.put('/api/payment-method/update/:id', PaymentMethodController.update)
|
app.put('/api/payment-method/update/:id', PaymentMethodController.update)
|
||||||
app.delete('/api/payment-method/delete/:id/:hard', PaymentMethodController.delete)
|
app.delete('/api/payment-method/delete/:id/:hard', PaymentMethodController.delete)
|
||||||
app.put('/api/payment-method/restore/:id', PaymentMethodController.restore)
|
app.put('/api/payment-method/restore/:id', PaymentMethodController.restore)
|
||||||
|
|
||||||
app.get('/api/registration-fee/detail', RegistrationFeeController.detail)
|
app.get('/api/registration-fee/detail', RegistrationFeeController.detail)
|
||||||
app.post('/api/registration-fee/create', RegistrationFeeController.create)
|
app.post('/api/registration-fee/create', RegistrationFeeController.create)
|
||||||
app.put('/api/registration-fee/update/:id', RegistrationFeeController.update)
|
app.put('/api/registration-fee/update/:id', RegistrationFeeController.update)
|
||||||
|
|
||||||
|
app.get('/api/region/province', RegionController.province)
|
||||||
|
app.get('/api/region/city/:province_code', RegionController.city)
|
||||||
|
app.get('/api/region/subdistrict/:city_code', RegionController.subdistrict)
|
||||||
|
app.get('/api/region/ward/:subdistric_code', RegionController.ward)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -319,6 +319,10 @@ const doc = {
|
|||||||
$aldeia: "Aldeia ID (UUID)",
|
$aldeia: "Aldeia ID (UUID)",
|
||||||
$phone: "Phone (string, max 30, optional)",
|
$phone: "Phone (string, max 30, optional)",
|
||||||
$default_room_id: "Default Room ID (UUID)",
|
$default_room_id: "Default Room ID (UUID)",
|
||||||
|
$province: "Province Code",
|
||||||
|
$city: "City Code",
|
||||||
|
$subdistrict: "Subdistrict Code",
|
||||||
|
$ward: "Ward Code",
|
||||||
},
|
},
|
||||||
item_price: {
|
item_price: {
|
||||||
$item_master_id: "Item Master ID (required, UUID)",
|
$item_master_id: "Item Master ID (required, UUID)",
|
||||||
|
|||||||
Reference in New Issue
Block a user