feat: check if profile exists
This commit is contained in:
parent
96b53a4ca5
commit
6e7086c085
4 changed files with 48 additions and 0 deletions
|
|
@ -23,11 +23,13 @@ import HttpStatus from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
|
||||
@Route("api/v1/org/profile/certificate")
|
||||
@Tags("ProfileCertificate")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileCertificateController extends Controller {
|
||||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
|
||||
private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory);
|
||||
|
||||
|
|
@ -110,6 +112,16 @@ export class ProfileCertificateController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileCertificate,
|
||||
) {
|
||||
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 ProfileCertificate();
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,11 +23,13 @@ import HttpStatus from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
|
||||
@Route("api/v1/org/profile/training")
|
||||
@Tags("ProfileTraining")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileTrainingController extends Controller {
|
||||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
private trainingRepo = AppDataSource.getRepository(ProfileTraining);
|
||||
private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory);
|
||||
|
||||
|
|
@ -123,6 +125,16 @@ export class ProfileTrainingController extends Controller {
|
|||
|
||||
@Post()
|
||||
public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileTraining) {
|
||||
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 ProfileTraining();
|
||||
const history = new ProfileTrainingHistory();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue