feat: check if profile exists

This commit is contained in:
Methapon2001 2024-03-12 17:17:16 +07:00
parent 96b53a4ca5
commit 6e7086c085
4 changed files with 48 additions and 0 deletions

View file

@ -23,11 +23,13 @@ import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
@Route("api/v1/org/profile/insignia")
@Tags("ProfileInsignia")
@Security("bearerAuth")
export class ProfileInsigniaController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory);
@ -131,6 +133,16 @@ export class ProfileInsigniaController extends Controller {
@Post()
public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileInsignia) {
if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
}
const profile = await this.profileRepo.findOneBy({ id: body.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const data = new ProfileInsignia();
const history = new ProfileInsigniaHistory();