35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
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,
|
|
};
|
|
}
|
|
|
|
export function whereAddressQuery(query: string) {
|
|
return [
|
|
{ address: { contains: query } },
|
|
{ addressEN: { contains: query } },
|
|
{ soi: { contains: query } },
|
|
{ soiEN: { contains: query } },
|
|
{ moo: { contains: query } },
|
|
{ mooEN: { contains: query } },
|
|
{ street: { contains: query } },
|
|
{ streetEN: { contains: query } },
|
|
{ province: { name: { contains: query } } },
|
|
{ province: { nameEN: { contains: query } } },
|
|
{ district: { name: { contains: query } } },
|
|
{ district: { nameEN: { contains: query } } },
|
|
{ subDistrict: { name: { contains: query } } },
|
|
{ subDistrict: { nameEN: { contains: query } } },
|
|
{ subDistrict: { zipCode: { contains: query } } },
|
|
];
|
|
}
|
|
|
|
export function queryOrNot<T>(query: string | boolean, where: T): T | undefined;
|
|
export function queryOrNot<T, U>(query: string | boolean, where: T, fallback: U): T | U;
|
|
export function queryOrNot<T, U>(query: string | boolean, where: T, fallback?: U) {
|
|
return !!query ? where : fallback;
|
|
}
|