refactor: update branch endpoint
This commit is contained in:
parent
eaa41f49be
commit
63293b671b
2 changed files with 15 additions and 10 deletions
|
|
@ -14,17 +14,10 @@ import {
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
|
|
||||||
import prisma from "../db";
|
import prisma from "../db";
|
||||||
import minio from "../services/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";
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
|
|
||||||
if (!process.env.MINIO_BUCKET) {
|
|
||||||
throw Error("Require MinIO bucket.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
|
||||||
|
|
||||||
type BranchContactCreate = {
|
type BranchContactCreate = {
|
||||||
telephoneNo: string;
|
telephoneNo: string;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,8 @@ type BranchCreate = {
|
||||||
address: string;
|
address: string;
|
||||||
zipCode: string;
|
zipCode: string;
|
||||||
email: string;
|
email: string;
|
||||||
telephoneNo: string;
|
contactName: string;
|
||||||
|
telephoneNo: string | string[];
|
||||||
lineId: string;
|
lineId: string;
|
||||||
longitude: string;
|
longitude: string;
|
||||||
latitude: string;
|
latitude: string;
|
||||||
|
|
@ -55,7 +56,8 @@ type BranchUpdate = {
|
||||||
address?: string;
|
address?: string;
|
||||||
zipCode?: string;
|
zipCode?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
telephoneNo?: string;
|
contactName?: string;
|
||||||
|
telephoneNo?: string | string[];
|
||||||
lineId?: string;
|
lineId?: string;
|
||||||
longitude?: string;
|
longitude?: string;
|
||||||
latitude?: string;
|
latitude?: string;
|
||||||
|
|
@ -238,7 +240,7 @@ export class BranchController extends Controller {
|
||||||
"missing_or_invalid_parameter",
|
"missing_or_invalid_parameter",
|
||||||
);
|
);
|
||||||
|
|
||||||
const { provinceId, districtId, subDistrictId, headOfficeId, ...rest } = body;
|
const { provinceId, districtId, subDistrictId, headOfficeId, telephoneNo, ...rest } = body;
|
||||||
|
|
||||||
const year = new Date().getFullYear();
|
const year = new Date().getFullYear();
|
||||||
|
|
||||||
|
|
@ -279,7 +281,17 @@ export class BranchController extends Controller {
|
||||||
|
|
||||||
this.setStatus(HttpStatus.CREATED);
|
this.setStatus(HttpStatus.CREATED);
|
||||||
|
|
||||||
|
if (record && telephoneNo) {
|
||||||
|
await prisma.branchContact.createMany({
|
||||||
|
data:
|
||||||
|
typeof telephoneNo === "string"
|
||||||
|
? [{ telephoneNo, branchId: record.id }]
|
||||||
|
: telephoneNo.map((v) => ({ telephoneNo: v, branchId: record.id })),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return Object.assign(record, {
|
return Object.assign(record, {
|
||||||
|
contact: await prisma.branchContact.findMany({ where: { branchId: record.id } }),
|
||||||
qrCodeImageUrl: await minio.presignedGetObject(
|
qrCodeImageUrl: await minio.presignedGetObject(
|
||||||
MINIO_BUCKET,
|
MINIO_BUCKET,
|
||||||
lineImageLoc(record.id),
|
lineImageLoc(record.id),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue