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

@ -19,11 +19,13 @@ import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
@Route("api/v1/org/profile/honor")
@Tags("ProfileHonor")
@Security("bearerAuth")
export class ProfileHonorController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
private honorRepo = AppDataSource.getRepository(ProfileHonor);
private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory);
@ -104,6 +106,16 @@ export class ProfileHonorController extends Controller {
@Post()
public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileHonor) {
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 ProfileHonor();
const history = new ProfileHonorHistory();