feat: deprecate unused endpoints
This commit is contained in:
parent
ed832148fc
commit
2f73dd1634
3 changed files with 5 additions and 104 deletions
|
|
@ -20,7 +20,7 @@ import HttpStatus from "../interfaces/http-status";
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
import minio from "../services/minio";
|
import minio from "../services/minio";
|
||||||
import { isSystem } from "../utils/keycloak";
|
import { isSystem } from "../utils/keycloak";
|
||||||
import { deleteFile, fileLocation, listFile } from "../utils/minio";
|
import { deleteFile, deleteFolder, fileLocation, listFile } from "../utils/minio";
|
||||||
import { createPermCheck } from "../services/permission";
|
import { createPermCheck } from "../services/permission";
|
||||||
import { filterStatus } from "../services/prisma";
|
import { filterStatus } from "../services/prisma";
|
||||||
|
|
||||||
|
|
@ -653,15 +653,10 @@ export class BranchController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
|
deleteFolder(fileLocation.branch.img(branchId)),
|
||||||
minio.removeObject(MINIO_BUCKET, fileLocation.branch.line(branchId), {
|
minio.removeObject(MINIO_BUCKET, fileLocation.branch.line(branchId), {
|
||||||
forceDelete: true,
|
forceDelete: true,
|
||||||
}),
|
}),
|
||||||
minio.removeObject(MINIO_BUCKET, fileLocation.branch.image(branchId), {
|
|
||||||
forceDelete: true,
|
|
||||||
}),
|
|
||||||
minio.removeObject(MINIO_BUCKET, fileLocation.branch.map(branchId), {
|
|
||||||
forceDelete: true,
|
|
||||||
}),
|
|
||||||
...data.bank.map(async (v) => {
|
...data.bank.map(async (v) => {
|
||||||
await minio.removeObject(MINIO_BUCKET, fileLocation.branch.bank(branchId, v.id), {
|
await minio.removeObject(MINIO_BUCKET, fileLocation.branch.bank(branchId, v.id), {
|
||||||
forceDelete: true,
|
forceDelete: true,
|
||||||
|
|
@ -704,63 +699,6 @@ export class BranchController extends Controller {
|
||||||
await deleteFile(fileLocation.branch.line(branchId));
|
await deleteFile(fileLocation.branch.line(branchId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("{branchId}/branch-image")
|
|
||||||
async getBranchImageByBranchId(@Request() req: RequestWithUser, @Path() branchId: string) {
|
|
||||||
const url = await minio.presignedGetObject(
|
|
||||||
MINIO_BUCKET,
|
|
||||||
fileLocation.branch.image(branchId),
|
|
||||||
60 * 60,
|
|
||||||
);
|
|
||||||
return req.res?.redirect(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put("{branchId}/branch-image")
|
|
||||||
@Security("keycloak", MANAGE_ROLES.concat("admin", "branch_manager"))
|
|
||||||
async setBranchImageByBranchId(@Request() req: RequestWithUser, @Path() branchId: string) {
|
|
||||||
await permissionCheck(req.user, branchId);
|
|
||||||
return req.res?.redirect(
|
|
||||||
await minio.presignedPutObject(
|
|
||||||
MINIO_BUCKET,
|
|
||||||
fileLocation.branch.image(branchId),
|
|
||||||
12 * 60 * 60,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete("{branchId}/branch-image")
|
|
||||||
@Security("keycloak", MANAGE_ROLES.concat("admin", "branch_manager"))
|
|
||||||
async deleteBranchImage(@Request() req: RequestWithUser, @Path() branchId: string) {
|
|
||||||
await permissionCheck(req.user, branchId);
|
|
||||||
await deleteFile(fileLocation.branch.image(branchId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get("{branchId}/map-image")
|
|
||||||
async getMapImageByBranchId(@Request() req: RequestWithUser, @Path() branchId: string) {
|
|
||||||
const url = await minio.presignedGetObject(
|
|
||||||
MINIO_BUCKET,
|
|
||||||
fileLocation.branch.image(branchId),
|
|
||||||
60 * 60,
|
|
||||||
);
|
|
||||||
return req.res?.redirect(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put("{branchId}/map-image")
|
|
||||||
@Security("keycloak", MANAGE_ROLES.concat("admin", "branch_manager"))
|
|
||||||
async setMapImageByBranchId(@Request() req: RequestWithUser, @Path() branchId: string) {
|
|
||||||
await permissionCheck(req.user, branchId);
|
|
||||||
|
|
||||||
return req.res?.redirect(
|
|
||||||
await minio.presignedPutObject(MINIO_BUCKET, fileLocation.branch.map(branchId), 12 * 60 * 60),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Delete("{branchId}/map-image")
|
|
||||||
@Security("keycloak", MANAGE_ROLES.concat("admin", "branch_manager"))
|
|
||||||
async deleteMapImage(@Request() req: RequestWithUser, @Path() branchId: string) {
|
|
||||||
await permissionCheck(req.user, branchId);
|
|
||||||
await deleteFile(fileLocation.branch.map(branchId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get("{branchId}/bank-qr/{bankId}")
|
@Get("{branchId}/bank-qr/{bankId}")
|
||||||
async getBankQRByBranchIdAndBankId(
|
async getBankQRByBranchIdAndBankId(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import {
|
||||||
import { Branch, Prisma, Status, User, UserType } from "@prisma/client";
|
import { Branch, Prisma, Status, User, UserType } from "@prisma/client";
|
||||||
|
|
||||||
import prisma from "../db";
|
import prisma from "../db";
|
||||||
import minio from "../services/minio";
|
import minio, { deleteFolder } from "../services/minio";
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatus from "../interfaces/http-status";
|
import HttpStatus from "../interfaces/http-status";
|
||||||
|
|
@ -229,10 +229,6 @@ async function userBranchCodeGen(user: User, branch: Branch) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function imageLocation(id: string) {
|
|
||||||
return `user/profile-img-${id}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Route("api/v1/user")
|
@Route("api/v1/user")
|
||||||
@Tags("User")
|
@Tags("User")
|
||||||
export class UserController extends Controller {
|
export class UserController extends Controller {
|
||||||
|
|
@ -872,24 +868,8 @@ export class UserController extends Controller {
|
||||||
throw new HttpError(HttpStatus.FORBIDDEN, "User is in used.", "userInUsed");
|
throw new HttpError(HttpStatus.FORBIDDEN, "User is in used.", "userInUsed");
|
||||||
}
|
}
|
||||||
|
|
||||||
await minio.removeObject(MINIO_BUCKET, imageLocation(userId), {
|
await deleteFolder(MINIO_BUCKET, fileLocation.user.profile(userId));
|
||||||
forceDelete: true,
|
await deleteFolder(MINIO_BUCKET, fileLocation.user.attachment(userId));
|
||||||
});
|
|
||||||
|
|
||||||
new Promise<string[]>((resolve, reject) => {
|
|
||||||
const item: string[] = [];
|
|
||||||
|
|
||||||
const stream = minio.listObjectsV2(MINIO_BUCKET, fileLocation.user.attachment(userId));
|
|
||||||
|
|
||||||
stream.on("data", (v) => v && v.name && item.push(v.name));
|
|
||||||
stream.on("end", () => resolve(item));
|
|
||||||
stream.on("error", () => reject(new Error("MinIO error.")));
|
|
||||||
}).then((list) => {
|
|
||||||
list.map(async (v) => {
|
|
||||||
await minio.removeObject(MINIO_BUCKET, v, { forceDelete: true });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
await deleteUser(userId);
|
await deleteUser(userId);
|
||||||
|
|
||||||
return await prisma.user.delete({
|
return await prisma.user.delete({
|
||||||
|
|
@ -903,21 +883,6 @@ export class UserController extends Controller {
|
||||||
where: { id: userId },
|
where: { id: userId },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("{userId}/image")
|
|
||||||
async getUserImageByUserId(@Request() req: RequestWithUser, @Path() userId: string) {
|
|
||||||
const url = await minio.presignedGetObject(MINIO_BUCKET, imageLocation(userId), 60 * 60);
|
|
||||||
return req.res?.redirect(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put("{userId}/image")
|
|
||||||
@Security("keycloak", ["system", "head_of_admin", "admin", "branch_manager"])
|
|
||||||
async setUserImageByUserId(@Request() req: RequestWithUser, @Path() userId: string) {
|
|
||||||
await permissionCheck(req.user, userId);
|
|
||||||
return req.res?.redirect(
|
|
||||||
await minio.presignedPutObject(MINIO_BUCKET, imageLocation(userId), 12 * 60 * 60),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Route("api/v1/user/{userId}/profile-image")
|
@Route("api/v1/user/{userId}/profile-image")
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,6 @@ export async function deleteFolder(path: string) {
|
||||||
export const fileLocation = {
|
export const fileLocation = {
|
||||||
branch: {
|
branch: {
|
||||||
line: (branchId: string) => `branch/line-qr-${branchId}`,
|
line: (branchId: string) => `branch/line-qr-${branchId}`,
|
||||||
image: (branchId: string) => `branch/branch-img-${branchId}`,
|
|
||||||
map: (branchId: string) => `branch/map-img-${branchId}`,
|
|
||||||
bank: (branchId: string, bankId: string) => `branch/bank-qr-${branchId}-${bankId}`,
|
bank: (branchId: string, bankId: string) => `branch/bank-qr-${branchId}-${bankId}`,
|
||||||
img: (branchId: string, name?: string) => `branch/img-${branchId}/${name || ""}`,
|
img: (branchId: string, name?: string) => `branch/img-${branchId}/${name || ""}`,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue