Merge branch 'net-dav' into develop
This commit is contained in:
commit
dc553379e1
2 changed files with 424 additions and 0 deletions
195
src/controllers/ProfileAssessmentsController.ts
Normal file
195
src/controllers/ProfileAssessmentsController.ts
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Query,
|
||||
Patch,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { CreateProfileAssessment, ProfileAssessment } from "../entities/ProfileAssessment";
|
||||
import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
@Route("api/v1/org/profile/assessments")
|
||||
@Tags("ProfileAssessments")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileAssessmentsController extends Controller {
|
||||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment);
|
||||
private profileAssessmentsHistoryRepository =
|
||||
AppDataSource.getRepository(ProfileAssessmentHistory);
|
||||
|
||||
@Get("{profileId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "f723bf42-a61c-4af4-ba8b-0e4ad0a89a80",
|
||||
createdAt: "2024-03-12T20:56:45.986Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T20:56:45.986Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "test bar",
|
||||
lastUpdateFullName: "test bar",
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
isActive: true,
|
||||
name: "สาวิตรี ศรีสมัย",
|
||||
date: "2024-03-13T03:55:42.000Z",
|
||||
point1: 0,
|
||||
point1Total: 0,
|
||||
point2: 0,
|
||||
point2Total: 0,
|
||||
pointSum: 0,
|
||||
pointSumTotal: 0,
|
||||
},
|
||||
],
|
||||
})
|
||||
public async detailProfileAssessments(@Path() profileId: string) {
|
||||
const getProfileAssessments = await this.profileAssessmentsRepository.findBy({ profileId });
|
||||
if (!getProfileAssessments) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(getProfileAssessments);
|
||||
}
|
||||
|
||||
@Get("history/{assessmentId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "47b3e370-be05-4469-a34f-e4a04747f54e",
|
||||
createdAt: "2024-03-12T20:59:39.774Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T20:59:39.774Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "test bar",
|
||||
isActive: true,
|
||||
name: "สาวิตรี ศรีสมัย",
|
||||
date: "2024-03-13T03:55:42.000Z",
|
||||
point1: 0,
|
||||
point1Total: 0,
|
||||
point2: 100,
|
||||
point2Total: 100,
|
||||
pointSum: 100,
|
||||
pointSumTotal: 100,
|
||||
profileAssessmentId: "f723bf42-a61c-4af4-ba8b-0e4ad0a89a80",
|
||||
},
|
||||
{
|
||||
id: "ecff89b1-9bef-49a9-83f5-8be3cecb8ca7",
|
||||
createdAt: "2024-03-12T20:58:19.450Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T20:58:19.450Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "test bar",
|
||||
isActive: true,
|
||||
name: "สาวิตรี ศรีสมัย",
|
||||
date: "2024-03-13T03:55:42.000Z",
|
||||
point1: 50,
|
||||
point1Total: 50,
|
||||
point2: 100,
|
||||
point2Total: 100,
|
||||
pointSum: 150,
|
||||
pointSumTotal: 150,
|
||||
profileAssessmentId: "f723bf42-a61c-4af4-ba8b-0e4ad0a89a80",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getProfileAssessmentsHistory(@Path() assessmentId: string) {
|
||||
const record = await this.profileAssessmentsHistoryRepository.findBy({
|
||||
profileAssessmentId: assessmentId,
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async profileAssessment(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileAssessment,
|
||||
) {
|
||||
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.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const data = new ProfileAssessment();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.profileAssessmentsRepository.save(data);
|
||||
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Patch("{assessmentId}")
|
||||
public async editProfileAssessment(
|
||||
@Body() requestBody: CreateProfileAssessment,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() assessmentId: string,
|
||||
) {
|
||||
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileAssessmentHistory();
|
||||
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(history, { ...requestBody, id: undefined });
|
||||
|
||||
history.profileAssessmentId = assessmentId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(record),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
]);
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Delete("{assessmentId}")
|
||||
public async deleteProfileAssessment(@Path() assessmentId: string) {
|
||||
await this.profileAssessmentsHistoryRepository.delete({
|
||||
profileAssessmentId: assessmentId,
|
||||
});
|
||||
|
||||
const result = await this.profileAssessmentsRepository.delete({ id: assessmentId });
|
||||
|
||||
if (result.affected && result.affected <= 0)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
229
src/controllers/ProfileEducationsController.ts
Normal file
229
src/controllers/ProfileEducationsController.ts
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Query,
|
||||
Patch,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
|
||||
import {
|
||||
ProfileEducation,
|
||||
CreateProfileEducation,
|
||||
UpdateProfileEducation,
|
||||
} from "../entities/ProfileEducation";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
|
||||
@Route("api/v1/org/profile/educations")
|
||||
@Tags("ProfileEducations")
|
||||
@Security("bearerAuth")
|
||||
export class ProfileEducationsController extends Controller {
|
||||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
private profileEducationRepo = AppDataSource.getRepository(ProfileEducation);
|
||||
private profileEducationHistoryRepo = AppDataSource.getRepository(ProfileEducationHistory);
|
||||
|
||||
@Get("{profileId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "f6c693b4-1a9b-4fbe-95c5-ed4da50d35b6",
|
||||
createdAt: "2024-03-12T20:26:42.621Z",
|
||||
createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
lastUpdatedAt: "2024-03-12T20:33:09.000Z",
|
||||
lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0",
|
||||
createdFullName: "test bar",
|
||||
lastUpdateFullName: "test bar",
|
||||
profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
|
||||
isActive: true,
|
||||
country: "string",
|
||||
degree: "ปวส",
|
||||
duration: "-",
|
||||
durationYear: 0,
|
||||
field: "ชางเทคนิค ชั้นสูง",
|
||||
finishDate: "2024-03-13T03:23:31.000Z",
|
||||
fundName: "-",
|
||||
gpa: "3.64",
|
||||
institute: "เทคโนเชียงใหม่",
|
||||
other: "string",
|
||||
startDate: "2024-03-13T03:23:31.000Z",
|
||||
endDate: "2024-03-13T03:23:31.000Z",
|
||||
educationLevel: "ปวส",
|
||||
educationLevelId: "string",
|
||||
positionPath: "string",
|
||||
positionPathId: "string",
|
||||
isDate: true,
|
||||
isEducation: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
public async detailProfileEducation(@Path() profileId: string) {
|
||||
const getProfileEducation = await this.profileEducationRepo.findBy({ profileId });
|
||||
if (!getProfileEducation) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(getProfileEducation);
|
||||
}
|
||||
|
||||
@Get("history/{educationId}")
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: [
|
||||
{
|
||||
id: "294aa117-6ce7-4c23-b5bd-fe1f12932c4a",
|
||||
createdAt: "2024-03-12T20:29:45.251Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T20:29:45.251Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "test bar",
|
||||
isActive: true,
|
||||
country: "string",
|
||||
degree: "ปวส",
|
||||
duration: "-",
|
||||
durationYear: 0,
|
||||
field: "ชางเทคนิค",
|
||||
finishDate: "2024-03-13T03:23:31.000Z",
|
||||
fundName: "-",
|
||||
gpa: "3.64",
|
||||
institute: "เทคโนเชียงใหม่",
|
||||
other: "string",
|
||||
startDate: "2024-03-13T03:23:31.000Z",
|
||||
endDate: "2024-03-13T03:23:31.000Z",
|
||||
educationLevel: "ปวส",
|
||||
educationLevelId: "string",
|
||||
positionPath: "string",
|
||||
positionPathId: "string",
|
||||
isDate: true,
|
||||
isEducation: true,
|
||||
profileEducationId: "f6c693b4-1a9b-4fbe-95c5-ed4da50d35b6",
|
||||
},
|
||||
{
|
||||
id: "2f00bd59-be3e-46d8-92a2-c4700baabf12",
|
||||
createdAt: "2024-03-12T20:33:09.128Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-12T20:33:09.128Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "test bar",
|
||||
isActive: true,
|
||||
country: "string",
|
||||
degree: "ปวส",
|
||||
duration: "-",
|
||||
durationYear: 0,
|
||||
field: "ชางเทคนิค ชั้นสูง",
|
||||
finishDate: "2024-03-13T03:23:31.000Z",
|
||||
fundName: "-",
|
||||
gpa: "3.64",
|
||||
institute: "เทคโนเชียงใหม่",
|
||||
other: "string",
|
||||
startDate: "2024-03-13T03:23:31.000Z",
|
||||
endDate: "2024-03-13T03:23:31.000Z",
|
||||
educationLevel: "ปวส",
|
||||
educationLevelId: "string",
|
||||
positionPath: "string",
|
||||
positionPathId: "string",
|
||||
isDate: true,
|
||||
isEducation: true,
|
||||
profileEducationId: "f6c693b4-1a9b-4fbe-95c5-ed4da50d35b6",
|
||||
},
|
||||
],
|
||||
})
|
||||
public async getProfileEducationHistory(@Path() educationId: string) {
|
||||
const record = await this.profileEducationHistoryRepo.findBy({
|
||||
profileEducationId: educationId,
|
||||
});
|
||||
if (!record) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
public async newProfileEducation(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileEducation,
|
||||
) {
|
||||
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 ProfileEducation();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
createdFullName: req.user.name,
|
||||
lastUpdateUserId: req.user.sub,
|
||||
lastUpdateFullName: req.user.name,
|
||||
};
|
||||
|
||||
Object.assign(data, { ...body, ...meta });
|
||||
|
||||
await this.profileEducationRepo.save(data);
|
||||
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Patch("{educationId}")
|
||||
public async editProfileEducation(
|
||||
@Body() requestBody: UpdateProfileEducation,
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() educationId: string,
|
||||
) {
|
||||
const record = await this.profileEducationRepo.findOneBy({ id: educationId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const history = new ProfileEducationHistory();
|
||||
|
||||
Object.assign(record, requestBody);
|
||||
Object.assign(history, { ...requestBody, id: undefined });
|
||||
|
||||
history.profileEducationId = educationId;
|
||||
history.lastUpdateFullName = req.user.name;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(record),
|
||||
this.profileEducationHistoryRepo.save(history),
|
||||
]);
|
||||
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Delete("{educationId}")
|
||||
public async deleteProfileEducation(@Path() educationId: string) {
|
||||
await this.profileEducationHistoryRepo.delete({
|
||||
profileEducationId: educationId,
|
||||
});
|
||||
|
||||
const result = await this.profileEducationRepo.delete({ id: educationId });
|
||||
|
||||
if (result.affected && result.affected <= 0)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
return this.setStatus(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue