This commit is contained in:
wayanrivan
2026-04-21 14:05:43 +07:00
parent df18b9cdfe
commit baf181d152
2 changed files with 17 additions and 17 deletions

View File

@ -187,9 +187,9 @@ export class ItemPriceController {
.required()
.label('Selling Price'),
expired_date: Joi.date()
.required()
.label('Expired Date'),
// expired_date: Joi.date()
// .required()
// .label('Expired Date'),
});
const param: any = await schema.validateAsync(req.body);
@ -198,8 +198,8 @@ export class ItemPriceController {
data.item_master = param.item_master_id
data.purchase_price = param.purchase_price
data.selling_price = param.selling_price
data.expired_date = param.expired_date
data.created_by = req.auth.data.name;
// data.expired_date = param.expired_date
data.created_by = req.auth?.data.name;
await OrmHelper.DB.manager.save(data);
@ -255,9 +255,9 @@ export class ItemPriceController {
.required()
.label('Selling Price'),
expired_date: Joi.date()
.required()
.label('Expired Date'),
// expired_date: Joi.date()
// .required()
// .label('Expired Date'),
});
req.body.id = req.params['id'];
@ -273,7 +273,7 @@ export class ItemPriceController {
data.purchase_price = param.purchase_price
data.selling_price = param.selling_price
data.expired_date = param.expired_date
data.updated_by = req.auth.data.name;
data.updated_by = req.auth?.data.name;
await repo.save(data);
@ -320,11 +320,11 @@ export class ItemPriceController {
const existData = await repo.findOne({ where: { id: param.id } });
if (existData && !param.hard) {
existData.deleted_by = req.auth.data.name;
existData.deleted_by = req.auth?.data.name;
await OrmHelper.DB.manager.save(existData);
}
const affected = (!param.hard ? await repo.softDelete({ id: param.id }) : await repo.delete({ id: param.id })).affected;
const affected = (!param.hard ? await repo.softDelete({ id: param.id }) : await repo.delete({ id: param.id })).affected || 0;
if (affected > 0) {
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_delete, {});
@ -362,7 +362,7 @@ export class ItemPriceController {
const repo = OrmHelper.DB.getRepository(ItemPrice);
const affected = (await repo.restore({ id: param.id })).affected;
const affected = (await repo.restore({ id: param.id })).affected || 0;
if (affected > 0) {
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_restore, {});

View File

@ -1,19 +1,19 @@
import { SelectQueryBuilder } from "typeorm";
import CommonHelper from "../helpers/common";
import { OrmHelper } from "../helpers/orm";
import { ItemPrice } from "entity";
import { ItemPrice,ItemMaster } from "entity";
export class ItemPriceModel {
static async list(filter = {}): Promise<SelectQueryBuilder<any>> {
const repo = OrmHelper.DB.getRepository(ItemPrice);
const repo = OrmHelper.DB.getRepository(ItemMaster);
let whereAttr: string[] = [];
let whereVal: any = {};
if (filter && Object.keys(filter).length > 0) {
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter, "item_price").whereAttr];
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter, "item_price").whereVal };
whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter, "item_master").whereAttr];
whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter, "item_master").whereVal };
}
var query = repo.createQueryBuilder("item_price").leftJoinAndSelect("item_price.item_master", "item_master");
var query = repo.createQueryBuilder("item_master").leftJoinAndSelect("item_master.item_price", "item_price");
if (whereAttr.length != 0) {
query = query.where(whereAttr.join(" and "), whereVal);
}