sort edu by level
This commit is contained in:
parent
4b05629c29
commit
587fe5d5b6
11 changed files with 229 additions and 266 deletions
|
|
@ -44,7 +44,7 @@ export class ProfileEducationsController extends Controller {
|
|||
}
|
||||
const getProfileEducation = await this.profileEducationRepo.find({
|
||||
where: { profileId: profile.id },
|
||||
order: { createdAt: "ASC" },
|
||||
order: { level: "ASC" },
|
||||
});
|
||||
if (!getProfileEducation) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -59,7 +59,7 @@ export class ProfileEducationsController extends Controller {
|
|||
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId);
|
||||
const getProfileEducation = await this.profileEducationRepo.find({
|
||||
where: { profileId: profileId },
|
||||
order: { createdAt: "ASC" },
|
||||
order: { level: "ASC" },
|
||||
});
|
||||
if (!getProfileEducation) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -133,23 +133,18 @@ export class ProfileEducationsController extends Controller {
|
|||
const history = new ProfileEducationHistory();
|
||||
Object.assign(history, { ...data, id: undefined });
|
||||
|
||||
const education = await this.profileEducationRepo.findOne({
|
||||
select: ["id", "level", "profileId"],
|
||||
where: { profileId: body.profileId },
|
||||
order: { level: "DESC" },
|
||||
});
|
||||
data.level = education == null ? 1 : education.level + 1;
|
||||
await this.profileEducationRepo.save(data, { data: req });
|
||||
setLogDataDiff(req, { before, after: data });
|
||||
history.profileEducationId = data.id;
|
||||
await this.profileEducationHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
const education = await this.profileEducationRepo.find({
|
||||
select: ["id", "level"],
|
||||
where: { profileId: body.profileId },
|
||||
});
|
||||
|
||||
const sortLevel = education.map((data, i) => ({
|
||||
id: data.id,
|
||||
level: i + 1,
|
||||
}));
|
||||
await this.profileEducationRepo.save(sortLevel);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -187,17 +182,6 @@ export class ProfileEducationsController extends Controller {
|
|||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
const education = await this.profileEducationRepo.find({
|
||||
select: ["id", "level"],
|
||||
where: { profileId: record.profileId },
|
||||
});
|
||||
|
||||
const sortLevel = education.map((data, i) => ({
|
||||
id: data.id,
|
||||
level: i + 1,
|
||||
}));
|
||||
await this.profileEducationRepo.save(sortLevel);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -220,8 +204,9 @@ export class ProfileEducationsController extends Controller {
|
|||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const education = await this.profileEducationRepo.find({
|
||||
select: ["id", "level"],
|
||||
select: ["id", "level", "profileId"],
|
||||
where: { profileId: record?.profileId },
|
||||
order: { level: "ASC" },
|
||||
});
|
||||
|
||||
const sortLevel = education.map((data, i) => ({
|
||||
|
|
@ -240,7 +225,10 @@ export class ProfileEducationsController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Put("sort/{profileId}")
|
||||
async Sort(@Path() profileId: string, @Body() requestBody: { id: string[] }) {
|
||||
async Sort(
|
||||
@Path() profileId: string,
|
||||
@Body() requestBody: { data: { id: string; isUse: boolean }[] },
|
||||
) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { id: profileId },
|
||||
});
|
||||
|
|
@ -249,13 +237,14 @@ export class ProfileEducationsController extends Controller {
|
|||
}
|
||||
|
||||
const education = await this.profileEducationRepo.find({
|
||||
select: ["id", "level"],
|
||||
select: ["id", "level", "profileId", "isUse"],
|
||||
where: { profileId: profileId },
|
||||
});
|
||||
|
||||
const sortLevel = education.map((data) => ({
|
||||
id: data.id,
|
||||
level: requestBody.id.indexOf(data.id) + 1,
|
||||
level: requestBody.data.findIndex((x) => x.id == data.id) + 1,
|
||||
isUse: requestBody.data.find((x) => x.id == data.id)?.isUse ?? false,
|
||||
}));
|
||||
|
||||
await this.profileEducationRepo.save(sortLevel);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue