2024-09-10 15:42:56 +07:00
|
|
|
export function connectOrNot(id?: string | null) {
|
|
|
|
|
return { connect: id ? { id } : undefined };
|
|
|
|
|
}
|
|
|
|
|
export function connectOrDisconnect(id?: string | null) {
|
|
|
|
|
return {
|
|
|
|
|
connect: id ? { id } : undefined,
|
|
|
|
|
disconnect: id === null || undefined,
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-09-11 14:38:56 +07:00
|
|
|
|
|
|
|
|
export function whereAddressQuery(query: string) {
|
|
|
|
|
return [
|
2025-04-17 13:41:22 +07:00
|
|
|
{ address: { contains: query, mode: "insensitive" } },
|
|
|
|
|
{ addressEN: { contains: query, mode: "insensitive" } },
|
|
|
|
|
{ soi: { contains: query, mode: "insensitive" } },
|
|
|
|
|
{ soiEN: { contains: query, mode: "insensitive" } },
|
|
|
|
|
{ moo: { contains: query, mode: "insensitive" } },
|
|
|
|
|
{ mooEN: { contains: query, mode: "insensitive" } },
|
|
|
|
|
{ street: { contains: query, mode: "insensitive" } },
|
|
|
|
|
{ streetEN: { contains: query, mode: "insensitive" } },
|
|
|
|
|
{ province: { name: { contains: query, mode: "insensitive" } } },
|
|
|
|
|
{ province: { nameEN: { contains: query, mode: "insensitive" } } },
|
|
|
|
|
{ district: { name: { contains: query, mode: "insensitive" } } },
|
|
|
|
|
{ district: { nameEN: { contains: query, mode: "insensitive" } } },
|
|
|
|
|
{ subDistrict: { name: { contains: query, mode: "insensitive" } } },
|
|
|
|
|
{ subDistrict: { nameEN: { contains: query, mode: "insensitive" } } },
|
|
|
|
|
{ subDistrict: { zipCode: { contains: query, mode: "insensitive" } } },
|
|
|
|
|
] as const;
|
2024-09-11 14:38:56 +07:00
|
|
|
}
|
2024-10-24 17:48:54 +07:00
|
|
|
|
2025-04-17 13:41:22 +07:00
|
|
|
export function queryOrNot<T>(query: any, where: T): T | undefined;
|
|
|
|
|
export function queryOrNot<T, U>(query: any, where: T, fallback: U): T | U;
|
|
|
|
|
export function queryOrNot<T, U>(query: any, where: T, fallback?: U) {
|
2024-11-14 17:56:33 +07:00
|
|
|
return !!query ? where : fallback;
|
2024-10-24 17:48:54 +07:00
|
|
|
}
|
2025-04-17 13:41:22 +07:00
|
|
|
|
|
|
|
|
export function whereDateQuery(startDate: Date | undefined, endDate: Date | undefined) {
|
|
|
|
|
return {
|
|
|
|
|
createdAt: {
|
|
|
|
|
gte: startDate,
|
|
|
|
|
lte: endDate,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|