เพิ่้มและลบ api history/user

This commit is contained in:
AdisakKanthawilang 2024-05-28 09:30:14 +07:00
parent abc4aee8a4
commit 8d1de6365a
22 changed files with 512 additions and 466 deletions

View file

@ -79,29 +79,6 @@ export class ProfileAbilityController extends Controller {
return new HttpSuccess(getProfileAbilityId);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async getProfileAbilityHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.profileAbilityHistoryRepo.find({
where: {
histories: {
profileId: profile.id,
},
},
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{abilityId}")
@Example({

View file

@ -81,29 +81,6 @@ export class ProfileAbilityEmployeeController extends Controller {
return new HttpSuccess(getProfileAbilityId);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async getProfileAbilityHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.profileAbilityHistoryRepo.find({
where: {
histories: {
profileEmployeeId: profile.id,
},
},
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{abilityId}")
@Example({

View file

@ -87,35 +87,6 @@ export class ProfileAssessmentsController extends Controller {
return new HttpSuccess(getProfileAssessments);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async getProfileAssessmentsHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.profileAssessmentsHistoryRepository.find({
relations: {
histories: true,
},
where: {
histories: {
profileId: profile.id,
},
},
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{assessmentId}")
@Example({
status: 200,

View file

@ -89,35 +89,6 @@ export class ProfileAssessmentsEmployeeController extends Controller {
return new HttpSuccess(getProfileAssessments);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async getProfileAssessmentsHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.profileAssessmentsHistoryRepository.find({
relations: {
histories: true,
},
where: {
histories: {
profileEmployeeId: profile.id,
},
},
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(record);
}
@Get("history/{assessmentId}")
@Example({
status: 200,

View file

@ -72,27 +72,7 @@ export class ProfileCertificateController extends Controller {
return new HttpSuccess(record);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async certificateHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.certificateHistoryRepo.find({
where: {
histories: {
profileId: profile.id,
},
},
});
return new HttpSuccess(record);
}
@Get("history/{certificateId}")
@Example({
status: 200,

View file

@ -72,27 +72,6 @@ export class ProfileCertificateEmployeeController extends Controller {
return new HttpSuccess(record);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async certificateHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.certificateHistoryRepo.find({
where: {
histories: {
profileEmployeeId: profile.id,
},
},
});
return new HttpSuccess(record);
}
@Get("history/{certificateId}")
@Example({
status: 200,

View file

@ -70,37 +70,6 @@ export class ProfileChangeNameController extends Controller {
return new HttpSuccess(lists);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async changeNameHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.changeNameHistoryRepository.find({
where: {
histories: {
profileId: profile.id,
},
},
select: [
"id",
"prefix",
"firstName",
"lastName",
"status",
"lastUpdateFullName",
"lastUpdatedAt",
],
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
}
@Get("history/{changeNameId}")
@Example({
status: 200,

View file

@ -72,37 +72,6 @@ export class ProfileChangeNameEmployeeController extends Controller {
return new HttpSuccess(lists);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async changeNameHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.changeNameHistoryRepository.find({
where: {
histories: {
profileEmployeeId: profile.id,
},
},
select: [
"id",
"prefix",
"firstName",
"lastName",
"status",
"lastUpdateFullName",
"lastUpdatedAt",
],
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
}
@Get("history/{changeNameId}")
@Example({
status: 200,

View file

@ -75,39 +75,6 @@ export class ProfileDisciplineController extends Controller {
return new HttpSuccess(lists);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async disciplineHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.disciplineHistoryRepository.find({
where: {
histories: {
profileId: profile.id,
},
},
select: [
"id",
"date",
"level",
"detail",
"unStigma",
"refCommandNo",
"refCommandDate",
"lastUpdateFullName",
"lastUpdatedAt",
],
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
}
@Get("history/{disciplineId}")
@Example({
status: 200,

View file

@ -90,39 +90,6 @@ export class ProfileDisciplineEmployeeController extends Controller {
return new HttpSuccess(lists);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async disciplineHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.disciplineHistoryRepository.find({
where: {
histories: {
profileEmployeeId: profile.id,
},
},
select: [
"id",
"date",
"level",
"detail",
"unStigma",
"refCommandNo",
"refCommandDate",
"lastUpdateFullName",
"lastUpdatedAt",
],
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
}
@Get("history/{disciplineId}")
public async disciplineHistory(@Path() disciplineId: string) {
const record = await this.disciplineHistoryRepository.find({

View file

@ -82,40 +82,6 @@ export class ProfileDutyController extends Controller {
return new HttpSuccess(lists);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async dutyHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.dutyHistoryRepository.find({
where: {
histories: {
profileId: profile.id,
},
},
select: [
"id",
"dateStart",
"dateEnd",
"reference",
"detail",
"refCommandNo",
"refCommandDate",
"lastUpdateFullName",
"lastUpdatedAt",
],
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
}
@Get("history/{dutyId}")
@Example({
status: 200,

View file

@ -67,40 +67,6 @@ export class ProfileDutyEmployeeController extends Controller {
return new HttpSuccess(lists);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async dutyHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.dutyHistoryRepository.find({
where: {
histories: {
profileEmployeeId: profile.id,
},
},
select: [
"id",
"dateStart",
"dateEnd",
"reference",
"detail",
"refCommandNo",
"refCommandDate",
"lastUpdateFullName",
"lastUpdatedAt",
],
order: { createdAt: "DESC" },
});
return new HttpSuccess(record);
}
@Get("history/{dutyId}")
public async dutyHistory(@Path() dutyId: string) {
const record = await this.dutyHistoryRepository.find({

View file

@ -104,6 +104,51 @@ export class ProfileFamilyCoupleController extends Controller {
return new HttpSuccess(familyCouple);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyCoupleHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyCouple = await this.ProfileFamilyCouple.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: {
profileId: profile.id,
},
});
const mapData = familyCouple
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
couplePrefix: y.couplePrefix,
coupleFirstName: y.coupleFirstName,
coupleLastName: y.coupleLastName,
coupleLastNameOld: y.coupleLastNameOld,
coupleCareer: y.coupleCareer,
coupleCitizenId: y.coupleCitizenId,
coupleLive: y.coupleLive,
relationship: y.relationship,
profileFamilyCoupleId: y.profileFamilyCoupleId,
profileId: profile.id,
}));
return new HttpSuccess(mapData);
}
@Get("history/{profileId}")
@Example({
status: 200,

View file

@ -74,16 +74,24 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
})
public async getFamilyCouple(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
where: { id: profileEmployeeId },
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyCouple = await this.ProfileFamilyCouple.findOne({
select: [
"id", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld",
"coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileEmployeeId",
"id",
"couplePrefix",
"coupleFirstName",
"coupleLastName",
"coupleLastNameOld",
"coupleCareer",
"coupleCitizenId",
"coupleLive",
"relationship",
"profileEmployeeId",
],
where: { profileEmployeeId },
order: { lastUpdatedAt: "DESC" },
@ -92,6 +100,51 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
return new HttpSuccess(familyCouple);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyCoupleHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyCouple = await this.ProfileFamilyCouple.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: {
profileEmployeeId: profile.id,
},
});
const mapData = familyCouple
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
couplePrefix: y.couplePrefix,
coupleFirstName: y.coupleFirstName,
coupleLastName: y.coupleLastName,
coupleLastNameOld: y.coupleLastNameOld,
coupleCareer: y.coupleCareer,
coupleCitizenId: y.coupleCitizenId,
coupleLive: y.coupleLive,
relationship: y.relationship,
profileFamilyCoupleId: y.profileFamilyCoupleId,
profileEmployeeId: profile.id,
}));
return new HttpSuccess(mapData);
}
@Get("history/{profileEmployeeId}")
@Example({
status: 200,
@ -115,13 +168,13 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
relationship: "string",
profileFamilyCoupleId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}
},
],
})
public async familyCoupleHistory(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
where: { id: profileEmployeeId },
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
@ -129,28 +182,30 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
const familyCouple = await this.ProfileFamilyCouple.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profileEmployeeId},
where: { profileEmployeeId: profileEmployeeId },
});
const mapData = familyCouple.flatMap((x) => x.histories).map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
couplePrefix: y.couplePrefix,
coupleFirstName: y.coupleFirstName,
coupleLastName: y.coupleLastName,
coupleLastNameOld: y.coupleLastNameOld,
coupleCareer: y.coupleCareer,
coupleCitizenId: y.coupleCitizenId,
coupleLive: y.coupleLive,
relationship: y.relationship,
profileFamilyCoupleId: y.profileFamilyCoupleId,
profileEmployeeId: profileEmployeeId,
}));
const mapData = familyCouple
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
couplePrefix: y.couplePrefix,
coupleFirstName: y.coupleFirstName,
coupleLastName: y.coupleLastName,
coupleLastNameOld: y.coupleLastNameOld,
coupleCareer: y.coupleCareer,
coupleCitizenId: y.coupleCitizenId,
coupleLive: y.coupleLive,
relationship: y.relationship,
profileFamilyCoupleId: y.profileFamilyCoupleId,
profileEmployeeId: profileEmployeeId,
}));
return new HttpSuccess(mapData);
}
@ -168,7 +223,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
familyCouple.createdUserId = req.user.sub;
familyCouple.createdFullName = req.user.name;
familyCouple.lastUpdateUserId = req.user.sub;
@ -176,7 +231,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
await this.ProfileFamilyCouple.save(familyCouple);
if (familyCouple) {
profile.relationship = familyCouple.relationship //update profileEmployee.relationship
profile.relationship = familyCouple.relationship; //update profileEmployee.relationship
const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), {
profileFamilyCoupleId: familyCouple.id,
couplePrefix: familyCouple.couplePrefix,
@ -194,7 +249,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
});
await Promise.all([
this.profileRepo.save(profile),
this.ProfileFamilyCoupleHistory.save(history)
this.ProfileFamilyCoupleHistory.save(history),
]);
}
return new HttpSuccess(familyCouple.id);
@ -206,26 +261,28 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
@Body() body: UpdateProfileFamilyCouple,
@Path() profileEmployeeId: string,
) {
const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileEmployeeId: profileEmployeeId });
const familyCouple = await this.ProfileFamilyCouple.findOneBy({
profileEmployeeId: profileEmployeeId,
});
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileFamilyCoupleHistory();
Object.assign(history, { ...familyCouple, id: undefined });
Object.assign(familyCouple, body);
familyCouple.lastUpdateUserId = req.user.sub,
familyCouple.lastUpdateFullName = req.user.name;
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
(familyCouple.lastUpdateUserId = req.user.sub),
(familyCouple.lastUpdateFullName = req.user.name);
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
history.profileFamilyCoupleId = familyCouple.id;
history.couplePrefix = familyCouple.couplePrefix,
history.coupleFirstName = familyCouple.coupleFirstName,
history.coupleLastName = familyCouple.coupleLastName,
history.coupleLastNameOld = familyCouple.coupleLastNameOld,
history.coupleCareer = familyCouple.coupleCareer,
history.coupleCitizenId = familyCouple.coupleCitizenId,
history.coupleLive = familyCouple.coupleLive,
history.relationship = familyCouple.relationship,
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
(history.couplePrefix = familyCouple.couplePrefix),
(history.coupleFirstName = familyCouple.coupleFirstName),
(history.coupleLastName = familyCouple.coupleLastName),
(history.coupleLastNameOld = familyCouple.coupleLastNameOld),
(history.coupleCareer = familyCouple.coupleCareer),
(history.coupleCitizenId = familyCouple.coupleCitizenId),
(history.coupleLive = familyCouple.coupleLive),
(history.relationship = familyCouple.relationship),
(history.lastUpdateUserId = req.user.sub),
(history.lastUpdateFullName = req.user.name);
await Promise.all([
this.ProfileFamilyCouple.save(familyCouple),
@ -234,5 +291,4 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
return new HttpSuccess();
}
}

View file

@ -98,6 +98,47 @@ export class ProfileFamilyFatherController extends Controller {
return new HttpSuccess(familyFather);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyFatherHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyFather = await this.ProfileFamilyFather.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileId: profile.id },
});
const mapData = familyFather
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
fatherPrefix: y.fatherPrefix,
fatherFirstName: y.fatherFirstName,
fatherLastName: y.fatherLastName,
fatherCareer: y.fatherCareer,
fatherCitizenId: y.fatherCitizenId,
fatherLive: y.fatherLive,
profileFamilyFatherId: y.profileFamilyFatherId,
profileId: profile.id,
}));
return new HttpSuccess(mapData);
}
@Get("history/{profileId}")
@Example({
status: 200,

View file

@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { ProfileFamilyFather, CreateProfileEmployeeFamilyFather, UpdateProfileFamilyFather } from "../entities/ProfileFamilyFather";
import {
ProfileFamilyFather,
CreateProfileEmployeeFamilyFather,
UpdateProfileFamilyFather,
} from "../entities/ProfileFamilyFather";
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
import Extension from "../interfaces/extension";
@Route("api/v1/org/profile-employee/family/father")
@ -70,16 +74,22 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
})
public async getFamilyFather(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
where: { id: profileEmployeeId },
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyFather = await this.ProfileFamilyFather.findOne({
select: [
"id", "fatherPrefix", "fatherFirstName", "fatherLastName",
"fatherCareer", "fatherCitizenId", "fatherLive", "profileEmployeeId",
"id",
"fatherPrefix",
"fatherFirstName",
"fatherLastName",
"fatherCareer",
"fatherCitizenId",
"fatherLive",
"profileEmployeeId",
],
where: { profileEmployeeId },
order: { lastUpdatedAt: "DESC" },
@ -88,6 +98,47 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
return new HttpSuccess(familyFather);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyFatherHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyFather = await this.ProfileFamilyFather.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profile.id },
});
const mapData = familyFather
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
fatherPrefix: y.fatherPrefix,
fatherFirstName: y.fatherFirstName,
fatherLastName: y.fatherLastName,
fatherCareer: y.fatherCareer,
fatherCitizenId: y.fatherCitizenId,
fatherLive: y.fatherLive,
profileFamilyFatherId: y.profileFamilyFatherId,
profileEmployeeId: profile.id,
}));
return new HttpSuccess(mapData);
}
@Get("history/{profileEmployeeId}")
@Example({
status: 200,
@ -109,13 +160,13 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
fatherLive: true,
profileFamilyFatherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}
},
],
})
public async familyFatherHistory(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
where: { id: profileEmployeeId },
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
@ -123,26 +174,28 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
const familyFather = await this.ProfileFamilyFather.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profileEmployeeId},
where: { profileEmployeeId: profileEmployeeId },
});
const mapData = familyFather.flatMap((x) => x.histories).map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
fatherPrefix: y.fatherPrefix,
fatherFirstName: y.fatherFirstName,
fatherLastName: y.fatherLastName,
fatherCareer: y.fatherCareer,
fatherCitizenId: y.fatherCitizenId,
fatherLive: y.fatherLive,
profileFamilyFatherId: y.profileFamilyFatherId,
profileEmployeeId: profileEmployeeId,
}));
const mapData = familyFather
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
fatherPrefix: y.fatherPrefix,
fatherFirstName: y.fatherFirstName,
fatherLastName: y.fatherLastName,
fatherCareer: y.fatherCareer,
fatherCitizenId: y.fatherCitizenId,
fatherLive: y.fatherLive,
profileFamilyFatherId: y.profileFamilyFatherId,
profileEmployeeId: profileEmployeeId,
}));
return new HttpSuccess(mapData);
}
@ -160,7 +213,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
familyFather.createdUserId = req.user.sub;
familyFather.createdFullName = req.user.name;
familyFather.lastUpdateUserId = req.user.sub;
@ -192,24 +245,26 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
@Body() body: UpdateProfileFamilyFather,
@Path() profileEmployeeId: string,
) {
const familyFather = await this.ProfileFamilyFather.findOneBy({ profileEmployeeId: profileEmployeeId });
const familyFather = await this.ProfileFamilyFather.findOneBy({
profileEmployeeId: profileEmployeeId,
});
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileFamilyFatherHistory();
Object.assign(history, { ...familyFather, id: undefined });
Object.assign(familyFather, body);
familyFather.lastUpdateUserId = req.user.sub,
familyFather.lastUpdateFullName = req.user.name;
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
(familyFather.lastUpdateUserId = req.user.sub),
(familyFather.lastUpdateFullName = req.user.name);
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
history.profileFamilyFatherId = familyFather.id;
history.fatherPrefix = familyFather.fatherPrefix,
history.fatherFirstName = familyFather.fatherFirstName,
history.fatherLastName = familyFather.fatherLastName,
history.fatherCareer = familyFather.fatherCareer,
history.fatherCitizenId = familyFather.fatherCitizenId,
history.fatherLive = familyFather.fatherLive,
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
(history.fatherPrefix = familyFather.fatherPrefix),
(history.fatherFirstName = familyFather.fatherFirstName),
(history.fatherLastName = familyFather.fatherLastName),
(history.fatherCareer = familyFather.fatherCareer),
(history.fatherCitizenId = familyFather.fatherCitizenId),
(history.fatherLive = familyFather.fatherLive),
(history.lastUpdateUserId = req.user.sub),
(history.lastUpdateFullName = req.user.name);
await Promise.all([
this.ProfileFamilyFather.save(familyFather),
@ -218,5 +273,4 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
return new HttpSuccess();
}
}

View file

@ -134,6 +134,38 @@ export class ProfileFamilyHistoryController extends Controller {
);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const family = await this.familyHistoryRepo.find({
order: { lastUpdatedAt: "DESC" },
where: {
profileId: profile.id
},
});
family.shift();
const record = await Promise.all(
family.map(async (v) => ({
...v,
children: await this.childrenHistoryRepo.find({
order: { createdAt: "ASC" },
}),
})),
);
return new HttpSuccess(record);
}
@Get("history/{profileId}")
@Example({
status: 200,

View file

@ -134,6 +134,38 @@ export class ProfileFamilyHistoryEmployeeController extends Controller {
);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const family = await this.familyHistoryRepo.find({
order: { lastUpdatedAt: "DESC" },
where: {
profileEmployeeId: profile.id,
},
});
family.shift();
const record = await Promise.all(
family.map(async (v) => ({
...v,
children: await this.childrenHistoryRepo.find({
order: { createdAt: "ASC" },
}),
})),
);
return new HttpSuccess(record);
}
@Get("history/{profileEmployeeId}")
@Example({
status: 200,

View file

@ -98,6 +98,47 @@ export class ProfileFamilyMotherController extends Controller {
return new HttpSuccess(familyMother);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyMotherHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyMother = await this.ProfileFamilyMother.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileId: profile.id },
});
const mapData = familyMother
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
motherPrefix: y.motherPrefix,
motherFirstName: y.motherFirstName,
motherLastName: y.motherLastName,
motherCareer: y.motherCareer,
motherCitizenId: y.motherCitizenId,
motherLive: y.motherLive,
profileFamilyMotherId: y.profileFamilyMotherId,
profileId: profile.id,
}));
return new HttpSuccess(mapData);
}
@Get("history/{profileId}")
@Example({
status: 200,

View file

@ -70,16 +70,22 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
})
public async getFamilyMother(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
where: { id: profileEmployeeId },
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyMother = await this.ProfileFamilyMother.findOne({
select: [
"id", "motherPrefix", "motherFirstName", "motherLastName",
"motherCareer", "motherCitizenId", "motherLive", "profileEmployeeId",
"id",
"motherPrefix",
"motherFirstName",
"motherLastName",
"motherCareer",
"motherCitizenId",
"motherLive",
"profileEmployeeId",
],
where: { profileEmployeeId },
order: { lastUpdatedAt: "DESC" },
@ -88,6 +94,47 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
return new HttpSuccess(familyMother);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async familyMotherHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const familyMother = await this.ProfileFamilyMother.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profile.id },
});
const mapData = familyMother
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
motherPrefix: y.motherPrefix,
motherFirstName: y.motherFirstName,
motherLastName: y.motherLastName,
motherCareer: y.motherCareer,
motherCitizenId: y.motherCitizenId,
motherLive: y.motherLive,
profileFamilyMotherId: y.profileFamilyMotherId,
profileEmployeeId: profile.id,
}));
return new HttpSuccess(mapData);
}
@Get("history/{profileEmployeeId}")
@Example({
status: 200,
@ -109,13 +156,13 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
motherLive: true,
profileFamilyMotherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}
},
],
})
public async familyMotherHistory(@Path() profileEmployeeId: string) {
const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }
})
where: { id: profileEmployeeId },
});
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
@ -123,26 +170,28 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
const familyMother = await this.ProfileFamilyMother.find({
relations: ["histories"],
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profileEmployeeId},
where: { profileEmployeeId: profileEmployeeId },
});
const mapData = familyMother.flatMap((x) => x.histories).map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
motherPrefix: y.motherPrefix,
motherFirstName: y.motherFirstName,
motherLastName: y.motherLastName,
motherCareer: y.motherCareer,
motherCitizenId: y.motherCitizenId,
motherLive: y.motherLive,
profileFamilyMotherId: y.profileFamilyMotherId,
profileEmployeeId: profileEmployeeId,
}));
const mapData = familyMother
.flatMap((x) => x.histories)
.map((y) => ({
id: y.id,
createdAt: y.createdAt,
createdUserId: y.createdUserId,
lastUpdatedAt: y.lastUpdatedAt,
lastUpdateUserId: y.lastUpdateUserId,
createdFullName: y.createdFullName,
lastUpdateFullName: y.lastUpdateFullName,
motherPrefix: y.motherPrefix,
motherFirstName: y.motherFirstName,
motherLastName: y.motherLastName,
motherCareer: y.motherCareer,
motherCitizenId: y.motherCitizenId,
motherLive: y.motherLive,
profileFamilyMotherId: y.profileFamilyMotherId,
profileEmployeeId: profileEmployeeId,
}));
return new HttpSuccess(mapData);
}
@ -160,7 +209,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
familyMother.createdUserId = req.user.sub;
familyMother.createdFullName = req.user.name;
familyMother.lastUpdateUserId = req.user.sub;
@ -192,24 +241,26 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
@Body() body: UpdateProfileFamilyMother,
@Path() profileEmployeeId: string,
) {
const familyMother = await this.ProfileFamilyMother.findOneBy({ profileEmployeeId: profileEmployeeId });
const familyMother = await this.ProfileFamilyMother.findOneBy({
profileEmployeeId: profileEmployeeId,
});
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const history = new ProfileFamilyMotherHistory();
Object.assign(history, { ...familyMother, id: undefined });
Object.assign(familyMother, body);
familyMother.lastUpdateUserId = req.user.sub,
familyMother.lastUpdateFullName = req.user.name;
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
(familyMother.lastUpdateUserId = req.user.sub),
(familyMother.lastUpdateFullName = req.user.name);
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
history.profileFamilyMotherId = familyMother.id;
history.motherPrefix = familyMother.motherPrefix,
history.motherFirstName = familyMother.motherFirstName,
history.motherLastName = familyMother.motherLastName,
history.motherCareer = familyMother.motherCareer,
history.motherCitizenId = familyMother.motherCitizenId,
history.motherLive = familyMother.motherLive,
history.lastUpdateUserId = req.user.sub,
history.lastUpdateFullName = req.user.name;
(history.motherPrefix = familyMother.motherPrefix),
(history.motherFirstName = familyMother.motherFirstName),
(history.motherLastName = familyMother.motherLastName),
(history.motherCareer = familyMother.motherCareer),
(history.motherCitizenId = familyMother.motherCitizenId),
(history.motherLive = familyMother.motherLive),
(history.lastUpdateUserId = req.user.sub),
(history.lastUpdateFullName = req.user.name);
await Promise.all([
this.ProfileFamilyMother.save(familyMother),
@ -218,5 +269,4 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
return new HttpSuccess();
}
}

View file

@ -218,6 +218,24 @@ export class ProfileGovernmentHistoryController extends Controller {
return new HttpSuccess(data);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async govHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.govRepo.find({
order: { lastUpdatedAt: "DESC" },
where: { profileId: profile.id },
});
return new HttpSuccess(record);
}
/**
*
* @summary

View file

@ -215,6 +215,24 @@ export class ProfileGovernmentEmployeeController extends Controller {
return new HttpSuccess(data);
}
/**
*
* @summary by keycloak
*
*/
@Get("history/user")
public async govHistoryUser(@Request() request: RequestWithUser) {
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
const record = await this.govRepo.find({
order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profile.id },
});
return new HttpSuccess(record);
}
/**
*
* @summary