feat: deprecate unused endpoints
This commit is contained in:
parent
ed832148fc
commit
2f73dd1634
3 changed files with 5 additions and 104 deletions
|
|
@ -15,7 +15,7 @@ import {
|
|||
import { Branch, Prisma, Status, User, UserType } from "@prisma/client";
|
||||
|
||||
import prisma from "../db";
|
||||
import minio from "../services/minio";
|
||||
import minio, { deleteFolder } from "../services/minio";
|
||||
import { RequestWithUser } from "../interfaces/user";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
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")
|
||||
@Tags("User")
|
||||
export class UserController extends Controller {
|
||||
|
|
@ -872,24 +868,8 @@ export class UserController extends Controller {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, "User is in used.", "userInUsed");
|
||||
}
|
||||
|
||||
await minio.removeObject(MINIO_BUCKET, imageLocation(userId), {
|
||||
forceDelete: true,
|
||||
});
|
||||
|
||||
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 deleteFolder(MINIO_BUCKET, fileLocation.user.profile(userId));
|
||||
await deleteFolder(MINIO_BUCKET, fileLocation.user.attachment(userId));
|
||||
await deleteUser(userId);
|
||||
|
||||
return await prisma.user.delete({
|
||||
|
|
@ -903,21 +883,6 @@ export class UserController extends Controller {
|
|||
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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue