search startDate and endDate
This commit is contained in:
parent
ee610c5686
commit
0aba9f9865
20 changed files with 123 additions and 32 deletions
|
|
@ -39,6 +39,7 @@ import {
|
||||||
connectOrNot,
|
connectOrNot,
|
||||||
queryOrNot,
|
queryOrNot,
|
||||||
whereAddressQuery,
|
whereAddressQuery,
|
||||||
|
whereDateQuery,
|
||||||
} from "../utils/relation";
|
} from "../utils/relation";
|
||||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||||
|
|
||||||
|
|
@ -250,6 +251,8 @@ export class BranchController extends Controller {
|
||||||
@Query() query: string = "",
|
@Query() query: string = "",
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
AND: {
|
AND: {
|
||||||
|
|
@ -285,6 +288,7 @@ export class BranchController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.BranchWhereInput;
|
} satisfies Prisma.BranchWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
@ -321,6 +325,7 @@ export class BranchController extends Controller {
|
||||||
district: true,
|
district: true,
|
||||||
subDistrict: true,
|
subDistrict: true,
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
orderBy: { code: "asc" },
|
orderBy: { code: "asc" },
|
||||||
}
|
}
|
||||||
: false,
|
: false,
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
import { branchRelationPermInclude, createPermCheck } from "../services/permission";
|
import { branchRelationPermInclude, createPermCheck } from "../services/permission";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "branch_manager"];
|
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "branch_manager"];
|
||||||
|
|
||||||
|
|
@ -97,6 +97,8 @@ export class UserBranchController extends Controller {
|
||||||
@Query() query: string = "",
|
@Query() query: string = "",
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
AND: {
|
AND: {
|
||||||
|
|
@ -107,6 +109,7 @@ export class UserBranchController extends Controller {
|
||||||
{ branch: { name: { contains: query, mode: "insensitive" } } },
|
{ branch: { name: { contains: query, mode: "insensitive" } } },
|
||||||
{ branch: { nameEN: { contains: query, mode: "insensitive" } } },
|
{ branch: { nameEN: { contains: query, mode: "insensitive" } } },
|
||||||
]),
|
]),
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.BranchUserWhereInput;
|
} satisfies Prisma.BranchUserWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
@ -150,6 +153,8 @@ export class BranchUserController extends Controller {
|
||||||
@Query() query: string = "",
|
@Query() query: string = "",
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
AND: {
|
AND: {
|
||||||
|
|
@ -164,6 +169,7 @@ export class BranchUserController extends Controller {
|
||||||
{ user: { email: { contains: query, mode: "insensitive" } } },
|
{ user: { email: { contains: query, mode: "insensitive" } } },
|
||||||
{ user: { telephoneNo: { contains: query, mode: "insensitive" } } },
|
{ user: { telephoneNo: { contains: query, mode: "insensitive" } } },
|
||||||
],
|
],
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.BranchUserWhereInput;
|
} satisfies Prisma.BranchUserWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ import {
|
||||||
connectOrNot,
|
connectOrNot,
|
||||||
queryOrNot,
|
queryOrNot,
|
||||||
whereAddressQuery,
|
whereAddressQuery,
|
||||||
|
whereDateQuery,
|
||||||
} from "../utils/relation";
|
} from "../utils/relation";
|
||||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||||
import { retry } from "../utils/func";
|
import { retry } from "../utils/func";
|
||||||
|
|
@ -305,6 +306,8 @@ export class UserController extends Controller {
|
||||||
@Query() status?: Status,
|
@Query() status?: Status,
|
||||||
@Query() responsibleDistrictId?: string,
|
@Query() responsibleDistrictId?: string,
|
||||||
@Query() activeBranchOnly?: boolean,
|
@Query() activeBranchOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
@Body()
|
@Body()
|
||||||
body?: {
|
body?: {
|
||||||
userId?: string[];
|
userId?: string[];
|
||||||
|
|
@ -368,6 +371,7 @@ export class UserController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.UserWhereInput;
|
} satisfies Prisma.UserWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import {
|
||||||
connectOrNot,
|
connectOrNot,
|
||||||
queryOrNot,
|
queryOrNot,
|
||||||
whereAddressQuery,
|
whereAddressQuery,
|
||||||
|
whereDateQuery,
|
||||||
} from "../utils/relation";
|
} from "../utils/relation";
|
||||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||||
import {
|
import {
|
||||||
|
|
@ -195,6 +196,8 @@ export class CustomerBranchController extends Controller {
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
@Query() activeRegisBranchOnly?: boolean,
|
@Query() activeRegisBranchOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.CustomerBranchWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.CustomerBranchWhereInput[]>(query, [
|
||||||
|
|
@ -229,6 +232,7 @@ export class CustomerBranchController extends Controller {
|
||||||
subDistrict: zipCode ? { zipCode } : undefined,
|
subDistrict: zipCode ? { zipCode } : undefined,
|
||||||
...filterStatus(activeRegisBranchOnly ? Status.ACTIVE : status),
|
...filterStatus(activeRegisBranchOnly ? Status.ACTIVE : status),
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.CustomerBranchWhereInput;
|
} satisfies Prisma.CustomerBranchWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
@ -285,6 +289,8 @@ export class CustomerBranchController extends Controller {
|
||||||
@Query() visa?: boolean,
|
@Query() visa?: boolean,
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.EmployeeWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.EmployeeWhereInput[]>(query, [
|
||||||
|
|
@ -300,6 +306,7 @@ export class CustomerBranchController extends Controller {
|
||||||
subDistrict: zipCode ? { zipCode } : undefined,
|
subDistrict: zipCode ? { zipCode } : undefined,
|
||||||
gender,
|
gender,
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.EmployeeWhereInput;
|
} satisfies Prisma.EmployeeWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ import {
|
||||||
setFile,
|
setFile,
|
||||||
} from "../utils/minio";
|
} from "../utils/minio";
|
||||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||||
import { connectOrNot, queryOrNot } from "../utils/relation";
|
import { connectOrNot, queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
const MANAGE_ROLES = [
|
const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
|
|
@ -165,6 +165,8 @@ export class CustomerController extends Controller {
|
||||||
@Query() includeBranch: boolean = false,
|
@Query() includeBranch: boolean = false,
|
||||||
@Query() company: boolean = false,
|
@Query() company: boolean = false,
|
||||||
@Query() activeBranchOnly?: boolean,
|
@Query() activeBranchOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.CustomerWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.CustomerWhereInput[]>(query, [
|
||||||
|
|
@ -188,6 +190,7 @@ export class CustomerController extends Controller {
|
||||||
: permissionCond(req.user, { activeOnly: activeBranchOnly }),
|
: permissionCond(req.user, { activeOnly: activeBranchOnly }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.CustomerWhereInput;
|
} satisfies Prisma.CustomerWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import {
|
||||||
connectOrNot,
|
connectOrNot,
|
||||||
queryOrNot,
|
queryOrNot,
|
||||||
whereAddressQuery,
|
whereAddressQuery,
|
||||||
|
whereDateQuery,
|
||||||
} from "../utils/relation";
|
} from "../utils/relation";
|
||||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||||
import {
|
import {
|
||||||
|
|
@ -154,6 +155,8 @@ export class EmployeeController extends Controller {
|
||||||
@Query() customerBranchId?: string,
|
@Query() customerBranchId?: string,
|
||||||
@Query() status?: Status,
|
@Query() status?: Status,
|
||||||
@Query() query: string = "",
|
@Query() query: string = "",
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
return await prisma.employee
|
return await prisma.employee
|
||||||
.groupBy({
|
.groupBy({
|
||||||
|
|
@ -183,6 +186,7 @@ export class EmployeeController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) =>
|
.then((res) =>
|
||||||
|
|
@ -240,6 +244,8 @@ export class EmployeeController extends Controller {
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
@Query() activeOnly?: boolean,
|
@Query() activeOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
@Body()
|
@Body()
|
||||||
body?: {
|
body?: {
|
||||||
passport?: string[];
|
passport?: string[];
|
||||||
|
|
@ -288,6 +294,7 @@ export class EmployeeController extends Controller {
|
||||||
subDistrict: zipCode ? { zipCode } : undefined,
|
subDistrict: zipCode ? { zipCode } : undefined,
|
||||||
gender,
|
gender,
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.EmployeeWhereInput;
|
} satisfies Prisma.EmployeeWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
import { notFoundError } from "../utils/error";
|
import { notFoundError } from "../utils/error";
|
||||||
import { filterStatus } from "../services/prisma";
|
import { filterStatus } from "../services/prisma";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
type WorkflowPayload = {
|
type WorkflowPayload = {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -58,6 +58,8 @@ export class FlowTemplateController extends Controller {
|
||||||
@Query() status?: Status,
|
@Query() status?: Status,
|
||||||
@Query() query = "",
|
@Query() query = "",
|
||||||
@Query() activeOnly?: boolean,
|
@Query() activeOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot(query, [
|
OR: queryOrNot(query, [
|
||||||
|
|
@ -74,6 +76,7 @@ export class FlowTemplateController extends Controller {
|
||||||
OR: permissionCondCompany(req.user, { activeOnly: true }),
|
OR: permissionCondCompany(req.user, { activeOnly: true }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.WorkflowTemplateWhereInput;
|
} satisfies Prisma.WorkflowTemplateWhereInput;
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
prisma.workflowTemplate.findMany({
|
prisma.workflowTemplate.findMany({
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import {
|
||||||
createPermCondition,
|
createPermCondition,
|
||||||
} from "../services/permission";
|
} from "../services/permission";
|
||||||
import { PaymentStatus } from "../generated/kysely/types";
|
import { PaymentStatus } from "../generated/kysely/types";
|
||||||
|
import { whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
type InvoicePayload = {
|
type InvoicePayload = {
|
||||||
quotationId: string;
|
quotationId: string;
|
||||||
|
|
@ -95,6 +96,8 @@ export class InvoiceController extends Controller {
|
||||||
@Query() quotationId?: string,
|
@Query() quotationId?: string,
|
||||||
@Query() debitNoteId?: string,
|
@Query() debitNoteId?: string,
|
||||||
@Query() pay?: boolean,
|
@Query() pay?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where: Prisma.InvoiceWhereInput = {
|
const where: Prisma.InvoiceWhereInput = {
|
||||||
OR: [
|
OR: [
|
||||||
|
|
@ -132,6 +135,7 @@ export class InvoiceController extends Controller {
|
||||||
OR: permissionCondCompany(req.user),
|
OR: permissionCondCompany(req.user),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
};
|
};
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import { isSystem } from "../utils/keycloak";
|
||||||
import { filterStatus } from "../services/prisma";
|
import { filterStatus } from "../services/prisma";
|
||||||
import { deleteFile, deleteFolder, fileLocation, getFile, listFile, setFile } from "../utils/minio";
|
import { deleteFile, deleteFolder, fileLocation, getFile, listFile, setFile } from "../utils/minio";
|
||||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
const MANAGE_ROLES = [
|
const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
|
|
@ -139,6 +139,8 @@ export class ProductController extends Controller {
|
||||||
@Query() orderField?: keyof Product,
|
@Query() orderField?: keyof Product,
|
||||||
@Query() orderBy?: "asc" | "desc",
|
@Query() orderBy?: "asc" | "desc",
|
||||||
@Query() activeOnly?: boolean,
|
@Query() activeOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
// NOTE: will be used to scope product within product group that is shared between branch but not company when select shared product if user is system
|
// NOTE: will be used to scope product within product group that is shared between branch but not company when select shared product if user is system
|
||||||
const targetGroup =
|
const targetGroup =
|
||||||
|
|
@ -194,6 +196,7 @@ export class ProductController extends Controller {
|
||||||
: []),
|
: []),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.ProductWhereInput;
|
} satisfies Prisma.ProductWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import {
|
||||||
} from "../services/permission";
|
} from "../services/permission";
|
||||||
import { filterStatus } from "../services/prisma";
|
import { filterStatus } from "../services/prisma";
|
||||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
type ProductGroupCreate = {
|
type ProductGroupCreate = {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -90,6 +90,8 @@ export class ProductGroup extends Controller {
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
@Query() activeOnly?: boolean,
|
@Query() activeOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.ProductGroupWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.ProductGroupWhereInput[]>(query, [
|
||||||
|
|
@ -105,6 +107,7 @@ export class ProductGroup extends Controller {
|
||||||
: { OR: permissionCond(req.user, { activeOnly }) },
|
: { OR: permissionCond(req.user, { activeOnly }) },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.ProductGroupWhereInput;
|
} satisfies Prisma.ProductGroupWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
import { notFoundError } from "../utils/error";
|
import { notFoundError } from "../utils/error";
|
||||||
import { filterStatus } from "../services/prisma";
|
import { filterStatus } from "../services/prisma";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
type PropertyPayload = {
|
type PropertyPayload = {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -49,6 +49,8 @@ export class PropertiesController extends Controller {
|
||||||
@Query() status?: Status,
|
@Query() status?: Status,
|
||||||
@Query() query = "",
|
@Query() query = "",
|
||||||
@Query() activeOnly?: boolean,
|
@Query() activeOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot(query, [
|
OR: queryOrNot(query, [
|
||||||
|
|
@ -61,6 +63,7 @@ export class PropertiesController extends Controller {
|
||||||
OR: permissionCondCompany(req.user, { activeOnly: true }),
|
OR: permissionCondCompany(req.user, { activeOnly: true }),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.PropertyWhereInput;
|
} satisfies Prisma.PropertyWhereInput;
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
prisma.property.findMany({
|
prisma.property.findMany({
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ import {
|
||||||
listFile,
|
listFile,
|
||||||
setFile,
|
setFile,
|
||||||
} from "../utils/minio";
|
} from "../utils/minio";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
const MANAGE_ROLES = [
|
const MANAGE_ROLES = [
|
||||||
"system",
|
"system",
|
||||||
|
|
@ -164,6 +164,8 @@ export class ServiceController extends Controller {
|
||||||
@Query() fullDetail?: boolean,
|
@Query() fullDetail?: boolean,
|
||||||
@Query() activeOnly?: boolean,
|
@Query() activeOnly?: boolean,
|
||||||
@Query() shared?: boolean,
|
@Query() shared?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
// NOTE: will be used to scope product within product group that is shared between branch but not company when select shared product if user is system
|
// NOTE: will be used to scope product within product group that is shared between branch but not company when select shared product if user is system
|
||||||
const targetGroup =
|
const targetGroup =
|
||||||
|
|
@ -219,6 +221,7 @@ export class ServiceController extends Controller {
|
||||||
: []),
|
: []),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.ServiceWhereInput;
|
} satisfies Prisma.ServiceWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import prisma from "../db";
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
import { isUsedError, notFoundError } from "../utils/error";
|
import { isUsedError, notFoundError } from "../utils/error";
|
||||||
|
import { whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
type WorkCreate = {
|
type WorkCreate = {
|
||||||
order: number;
|
order: number;
|
||||||
|
|
@ -45,9 +46,12 @@ export class WorkController extends Controller {
|
||||||
@Query() query: string = "",
|
@Query() query: string = "",
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: [{ name: { contains: query }, serviceId: baseOnly ? null : undefined }],
|
OR: [{ name: { contains: query }, serviceId: baseOnly ? null : undefined }],
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.WorkWhereInput;
|
} satisfies Prisma.WorkWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import {
|
||||||
import { isSystem } from "../utils/keycloak";
|
import { isSystem } from "../utils/keycloak";
|
||||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||||
import { precisionRound } from "../utils/arithmetic";
|
import { precisionRound } from "../utils/arithmetic";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
|
@ -206,6 +206,8 @@ export class QuotationController extends Controller {
|
||||||
@Query() forDebitNote?: boolean,
|
@Query() forDebitNote?: boolean,
|
||||||
@Query() code?: string,
|
@Query() code?: string,
|
||||||
@Query() query = "",
|
@Query() query = "",
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.QuotationWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.QuotationWhereInput[]>(query, [
|
||||||
|
|
@ -253,6 +255,7 @@ export class QuotationController extends Controller {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.QuotationWhereInput;
|
} satisfies Prisma.QuotationWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import {
|
||||||
createPermCheck,
|
createPermCheck,
|
||||||
createPermCondition,
|
createPermCondition,
|
||||||
} from "../services/permission";
|
} from "../services/permission";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
import { notFoundError } from "../utils/error";
|
import { notFoundError } from "../utils/error";
|
||||||
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
|
|
@ -81,6 +81,8 @@ export class RequestDataController extends Controller {
|
||||||
@Query() quotationId?: string,
|
@Query() quotationId?: string,
|
||||||
@Query() code?: string,
|
@Query() code?: string,
|
||||||
@Query() incomplete?: boolean,
|
@Query() incomplete?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.RequestDataWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.RequestDataWhereInput[]>(query, [
|
||||||
|
|
@ -147,6 +149,7 @@ export class RequestDataController extends Controller {
|
||||||
id: quotationId,
|
id: quotationId,
|
||||||
registeredBranch: { OR: permissionCond(req.user) },
|
registeredBranch: { OR: permissionCond(req.user) },
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.RequestDataWhereInput;
|
} satisfies Prisma.RequestDataWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ import {
|
||||||
listFile,
|
listFile,
|
||||||
setFile,
|
setFile,
|
||||||
} from "../utils/minio";
|
} from "../utils/minio";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "document_checker"];
|
const MANAGE_ROLES = ["system", "head_of_admin", "admin", "document_checker"];
|
||||||
|
|
||||||
|
|
@ -107,6 +107,8 @@ export class TaskController extends Controller {
|
||||||
@Query() assignedUserId?: string,
|
@Query() assignedUserId?: string,
|
||||||
@Query() taskOrderStatus?: TaskOrderStatus,
|
@Query() taskOrderStatus?: TaskOrderStatus,
|
||||||
@Body() body?: { code?: string[] },
|
@Body() body?: { code?: string[] },
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
taskOrderStatus,
|
taskOrderStatus,
|
||||||
|
|
@ -125,6 +127,7 @@ export class TaskController extends Controller {
|
||||||
{ contactName: { contains: query, mode: "insensitive" } },
|
{ contactName: { contains: query, mode: "insensitive" } },
|
||||||
{ contactTel: { contains: query, mode: "insensitive" } },
|
{ contactTel: { contains: query, mode: "insensitive" } },
|
||||||
]),
|
]),
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.TaskOrderWhereInput;
|
} satisfies Prisma.TaskOrderWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
@ -979,6 +982,8 @@ export class UserTaskController extends Controller {
|
||||||
@Query() page = 1,
|
@Query() page = 1,
|
||||||
@Query() pageSize = 30,
|
@Query() pageSize = 30,
|
||||||
@Query() userTaskStatus?: UserTaskStatus,
|
@Query() userTaskStatus?: UserTaskStatus,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
taskList: {
|
taskList: {
|
||||||
|
|
@ -1025,6 +1030,7 @@ export class UserTaskController extends Controller {
|
||||||
{ contactName: { contains: query, mode: "insensitive" } },
|
{ contactName: { contains: query, mode: "insensitive" } },
|
||||||
{ contactTel: { contains: query, mode: "insensitive" } },
|
{ contactTel: { contains: query, mode: "insensitive" } },
|
||||||
]),
|
]),
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.TaskOrderWhereInput;
|
} satisfies Prisma.TaskOrderWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ import {
|
||||||
} from "../utils/minio";
|
} from "../utils/minio";
|
||||||
import { notFoundError } from "../utils/error";
|
import { notFoundError } from "../utils/error";
|
||||||
import { CreditNotePaybackType, CreditNoteStatus, Prisma, RequestDataStatus } from "@prisma/client";
|
import { CreditNotePaybackType, CreditNoteStatus, Prisma, RequestDataStatus } from "@prisma/client";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
import { PaybackStatus, RequestWorkStatus } from "../generated/kysely/types";
|
import { PaybackStatus, RequestWorkStatus } from "../generated/kysely/types";
|
||||||
|
|
||||||
const MANAGE_ROLES = [
|
const MANAGE_ROLES = [
|
||||||
|
|
@ -143,6 +143,8 @@ export class CreditNoteController extends Controller {
|
||||||
@Query() quotationId?: string,
|
@Query() quotationId?: string,
|
||||||
@Query() creditNoteStatus?: CreditNoteStatus,
|
@Query() creditNoteStatus?: CreditNoteStatus,
|
||||||
@Body() body?: {},
|
@Body() body?: {},
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.CreditNoteWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.CreditNoteWhereInput[]>(query, [
|
||||||
|
|
@ -199,6 +201,7 @@ export class CreditNoteController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.CreditNoteWhereInput;
|
} satisfies Prisma.CreditNoteWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ import {
|
||||||
setFile,
|
setFile,
|
||||||
} from "../utils/minio";
|
} from "../utils/minio";
|
||||||
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
import { isUsedError, notFoundError, relationError } from "../utils/error";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
import { isSystem } from "../utils/keycloak";
|
import { isSystem } from "../utils/keycloak";
|
||||||
import { precisionRound } from "../utils/arithmetic";
|
import { precisionRound } from "../utils/arithmetic";
|
||||||
|
|
||||||
|
|
@ -196,6 +196,8 @@ export class DebitNoteController extends Controller {
|
||||||
@Query() includeRegisteredBranch?: boolean,
|
@Query() includeRegisteredBranch?: boolean,
|
||||||
@Query() code?: string,
|
@Query() code?: string,
|
||||||
@Body() body?: {},
|
@Body() body?: {},
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.QuotationWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.QuotationWhereInput[]>(query, [
|
||||||
|
|
@ -220,6 +222,7 @@ export class DebitNoteController extends Controller {
|
||||||
debitNoteQuotationId: quotationId,
|
debitNoteQuotationId: quotationId,
|
||||||
registeredBranch: isSystem(req.user) ? undefined : { OR: permissionCond(req.user) },
|
registeredBranch: isSystem(req.user) ? undefined : { OR: permissionCond(req.user) },
|
||||||
quotationStatus: status,
|
quotationStatus: status,
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.QuotationWhereInput;
|
} satisfies Prisma.QuotationWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import {
|
||||||
TaskStatus,
|
TaskStatus,
|
||||||
RequestWorkStatus,
|
RequestWorkStatus,
|
||||||
} from "@prisma/client";
|
} from "@prisma/client";
|
||||||
import { queryOrNot, whereAddressQuery } from "../utils/relation";
|
import { queryOrNot, whereAddressQuery, whereDateQuery } from "../utils/relation";
|
||||||
import { filterStatus } from "../services/prisma";
|
import { filterStatus } from "../services/prisma";
|
||||||
// import { RequestWorkStatus } from "../generated/kysely/types";
|
// import { RequestWorkStatus } from "../generated/kysely/types";
|
||||||
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
||||||
|
|
@ -51,6 +51,8 @@ export class LineController extends Controller {
|
||||||
@Query() page: number = 1,
|
@Query() page: number = 1,
|
||||||
@Query() pageSize: number = 30,
|
@Query() pageSize: number = 30,
|
||||||
@Query() activeOnly?: boolean,
|
@Query() activeOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: !!query
|
OR: !!query
|
||||||
|
|
@ -87,6 +89,7 @@ export class LineController extends Controller {
|
||||||
subDistrict: zipCode ? { zipCode } : undefined,
|
subDistrict: zipCode ? { zipCode } : undefined,
|
||||||
gender,
|
gender,
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.EmployeeWhereInput;
|
} satisfies Prisma.EmployeeWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
@ -173,6 +176,8 @@ export class LineController extends Controller {
|
||||||
@Query() requestDataStatus?: RequestDataStatus,
|
@Query() requestDataStatus?: RequestDataStatus,
|
||||||
@Query() quotationId?: string,
|
@Query() quotationId?: string,
|
||||||
@Query() code?: string,
|
@Query() code?: string,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR: queryOrNot<Prisma.RequestDataWhereInput[]>(query, [
|
OR: queryOrNot<Prisma.RequestDataWhereInput[]>(query, [
|
||||||
|
|
@ -247,6 +252,7 @@ export class LineController extends Controller {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.RequestDataWhereInput;
|
} satisfies Prisma.RequestDataWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
@ -604,6 +610,8 @@ export class LineController extends Controller {
|
||||||
@Query() includeRegisteredBranch?: boolean,
|
@Query() includeRegisteredBranch?: boolean,
|
||||||
@Query() code?: string,
|
@Query() code?: string,
|
||||||
@Query() query = "",
|
@Query() query = "",
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where = {
|
const where = {
|
||||||
OR:
|
OR:
|
||||||
|
|
@ -660,6 +668,7 @@ export class LineController extends Controller {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.QuotationWhereInput;
|
} satisfies Prisma.QuotationWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -10,26 +10,35 @@ export function connectOrDisconnect(id?: string | null) {
|
||||||
|
|
||||||
export function whereAddressQuery(query: string) {
|
export function whereAddressQuery(query: string) {
|
||||||
return [
|
return [
|
||||||
{ address: { contains: query } },
|
{ address: { contains: query, mode: "insensitive" } },
|
||||||
{ addressEN: { contains: query } },
|
{ addressEN: { contains: query, mode: "insensitive" } },
|
||||||
{ soi: { contains: query } },
|
{ soi: { contains: query, mode: "insensitive" } },
|
||||||
{ soiEN: { contains: query } },
|
{ soiEN: { contains: query, mode: "insensitive" } },
|
||||||
{ moo: { contains: query } },
|
{ moo: { contains: query, mode: "insensitive" } },
|
||||||
{ mooEN: { contains: query } },
|
{ mooEN: { contains: query, mode: "insensitive" } },
|
||||||
{ street: { contains: query } },
|
{ street: { contains: query, mode: "insensitive" } },
|
||||||
{ streetEN: { contains: query } },
|
{ streetEN: { contains: query, mode: "insensitive" } },
|
||||||
{ province: { name: { contains: query } } },
|
{ province: { name: { contains: query, mode: "insensitive" } } },
|
||||||
{ province: { nameEN: { contains: query } } },
|
{ province: { nameEN: { contains: query, mode: "insensitive" } } },
|
||||||
{ district: { name: { contains: query } } },
|
{ district: { name: { contains: query, mode: "insensitive" } } },
|
||||||
{ district: { nameEN: { contains: query } } },
|
{ district: { nameEN: { contains: query, mode: "insensitive" } } },
|
||||||
{ subDistrict: { name: { contains: query } } },
|
{ subDistrict: { name: { contains: query, mode: "insensitive" } } },
|
||||||
{ subDistrict: { nameEN: { contains: query } } },
|
{ subDistrict: { nameEN: { contains: query, mode: "insensitive" } } },
|
||||||
{ subDistrict: { zipCode: { contains: query } } },
|
{ subDistrict: { zipCode: { contains: query, mode: "insensitive" } } },
|
||||||
];
|
] as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function queryOrNot<T>(query: string | boolean, where: T): T | undefined;
|
export function queryOrNot<T>(query: any, where: T): T | undefined;
|
||||||
export function queryOrNot<T, U>(query: string | boolean, where: T, fallback: U): T | U;
|
export function queryOrNot<T, U>(query: any, where: T, fallback: U): T | U;
|
||||||
export function queryOrNot<T, U>(query: string | boolean, where: T, fallback?: U) {
|
export function queryOrNot<T, U>(query: any, where: T, fallback?: U) {
|
||||||
return !!query ? where : fallback;
|
return !!query ? where : fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function whereDateQuery(startDate: Date | undefined, endDate: Date | undefined) {
|
||||||
|
return {
|
||||||
|
createdAt: {
|
||||||
|
gte: startDate,
|
||||||
|
lte: endDate,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue