refactor: move field
This commit is contained in:
parent
155bb19b9b
commit
6b6f9e9de0
1 changed files with 4 additions and 46 deletions
|
|
@ -26,19 +26,13 @@ if (!process.env.MINIO_BUCKET) {
|
||||||
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
const MINIO_BUCKET = process.env.MINIO_BUCKET;
|
||||||
|
|
||||||
type BranchContactCreate = {
|
type BranchContactCreate = {
|
||||||
lineId: string;
|
|
||||||
telephoneNo: string;
|
telephoneNo: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type BranchContactUpdate = {
|
type BranchContactUpdate = {
|
||||||
lineId?: string;
|
|
||||||
telephoneNo?: string;
|
telephoneNo?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function imageLocation(id: string) {
|
|
||||||
return `branch/contact-${id}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Route("api/branch/{branchId}/contact")
|
@Route("api/branch/{branchId}/contact")
|
||||||
@Tags("Branch Contact")
|
@Tags("Branch Contact")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
|
|
@ -60,16 +54,7 @@ export class BranchContactController extends Controller {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result: await Promise.all(
|
result,
|
||||||
result.map(async (v) => ({
|
|
||||||
...v,
|
|
||||||
qrCodeImageUrl: await minio.presignedGetObject(
|
|
||||||
MINIO_BUCKET,
|
|
||||||
imageLocation(v.id),
|
|
||||||
12 * 60 * 60,
|
|
||||||
),
|
|
||||||
})),
|
|
||||||
),
|
|
||||||
page,
|
page,
|
||||||
pageSize,
|
pageSize,
|
||||||
total,
|
total,
|
||||||
|
|
@ -88,9 +73,7 @@ export class BranchContactController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.assign(record, {
|
return record;
|
||||||
qrCodeImageUrl: await minio.presignedGetObject(MINIO_BUCKET, imageLocation(record.id)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
|
@ -112,18 +95,7 @@ export class BranchContactController extends Controller {
|
||||||
|
|
||||||
this.setStatus(HttpStatus.CREATED);
|
this.setStatus(HttpStatus.CREATED);
|
||||||
|
|
||||||
return Object.assign(record, {
|
return record;
|
||||||
qrCodeImageUrl: await minio.presignedGetObject(
|
|
||||||
MINIO_BUCKET,
|
|
||||||
imageLocation(record.id),
|
|
||||||
12 * 60 * 60,
|
|
||||||
),
|
|
||||||
qrCodeImageUploadUrl: await minio.presignedPutObject(
|
|
||||||
MINIO_BUCKET,
|
|
||||||
imageLocation(record.id),
|
|
||||||
12 * 60 * 60,
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put("{contactId}")
|
@Put("{contactId}")
|
||||||
|
|
@ -150,18 +122,7 @@ export class BranchContactController extends Controller {
|
||||||
where: { id: contactId, branchId },
|
where: { id: contactId, branchId },
|
||||||
});
|
});
|
||||||
|
|
||||||
return Object.assign(record, {
|
return record;
|
||||||
qrCodeImageUrl: await minio.presignedGetObject(
|
|
||||||
MINIO_BUCKET,
|
|
||||||
imageLocation(record.id),
|
|
||||||
12 * 60 * 60,
|
|
||||||
),
|
|
||||||
qrCodeImageUploadUrl: await minio.presignedPutObject(
|
|
||||||
MINIO_BUCKET,
|
|
||||||
imageLocation(record.id),
|
|
||||||
12 * 60 * 60,
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("{contactId}")
|
@Delete("{contactId}")
|
||||||
|
|
@ -174,8 +135,5 @@ export class BranchContactController extends Controller {
|
||||||
"data_not_found",
|
"data_not_found",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await minio.removeObject(MINIO_BUCKET, imageLocation(contactId), {
|
|
||||||
forceDelete: true,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue