แก้ไขกลุ่มงาน
This commit is contained in:
parent
c86a88d32b
commit
5578bd4f18
2 changed files with 12 additions and 15 deletions
|
|
@ -18,6 +18,7 @@ import {
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Like, Not } from "typeorm";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { KpiGroup, creatKpiGroup, updateKpiGroup } from "../entities/kpiGroup";
|
||||
@Route("api/v1/kpi/group")
|
||||
|
|
@ -34,7 +35,6 @@ export class kpiGroupController extends Controller {
|
|||
/**
|
||||
* API สร้างกลุ่มงาน
|
||||
* @param requestBody
|
||||
* @param request
|
||||
* @returns
|
||||
*/
|
||||
@Post()
|
||||
|
|
@ -46,12 +46,12 @@ export class kpiGroupController extends Controller {
|
|||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiGroup = Object.assign(new KpiGroup(), requestBody);
|
||||
const ChkkpinameGroup = await this.kpiGroupRepository.findOne({
|
||||
const chkkpinameGroup = await this.kpiGroupRepository.findOne({
|
||||
where: {
|
||||
nameGroupKPI: requestBody.nameGroupKPI,
|
||||
},
|
||||
});
|
||||
if (ChkkpinameGroup) {
|
||||
if (chkkpinameGroup) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกลุ่มงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
kpiGroup.createdUserId = request.user.sub;
|
||||
|
|
@ -79,16 +79,15 @@ export class kpiGroupController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้");
|
||||
}
|
||||
|
||||
const ChkkpinameGroup = await this.kpiGroupRepository.findOne({
|
||||
const chkkpinameGroup = await this.kpiGroupRepository.findOne({
|
||||
where: {
|
||||
nameGroupKPI: requestBody.nameGroupKPI,
|
||||
},
|
||||
});
|
||||
if (ChkkpinameGroup) {
|
||||
if (chkkpinameGroup) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อกลุ่มงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
requestBody.nameGroupKPI = requestBody.nameGroupKPI;
|
||||
this.kpiGroupRepository.merge(kpiGroup, requestBody);
|
||||
kpiGroup.lastUpdateUserId = request.user.sub;
|
||||
kpiGroup.lastUpdateFullName = request.user.name;
|
||||
|
|
@ -136,20 +135,17 @@ export class kpiGroupController extends Controller {
|
|||
* API list กลุ่มงาน
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @param year
|
||||
* @param keyword
|
||||
*/
|
||||
@Get()
|
||||
async listKpiGroup(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("year") year?: string,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const [kpiGroup, total] = await this.kpiGroupRepository.findAndCount({
|
||||
// where: {
|
||||
// name: Like(`%${keyword}%`),
|
||||
// },
|
||||
where: {
|
||||
nameGroupKPI: Like(`%${keyword}%`),
|
||||
},
|
||||
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import HttpSuccess from "../interfaces/http-success";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { KpiPeriod, createKpiPeriod, updateKpiPeriod } from "../entities/kpiPeriod";
|
||||
import { Like } from "typeorm/browser";
|
||||
|
||||
@Route("api/v1/kpi/period")
|
||||
@Tags("kpiPeriod")
|
||||
|
|
@ -176,9 +177,9 @@ export class kpiController extends Controller {
|
|||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const [kpiPeriod, total] = await this.kpiPeriodRepository.findAndCount({
|
||||
// where: {
|
||||
// name: Like(`%${keyword}%`),
|
||||
// },
|
||||
// where: {
|
||||
// durationKPI: Like(`%${keyword}%`),
|
||||
// },
|
||||
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue