Merge branch 'develop' into adiDev

# Conflicts:
#	src/controllers/ProfileController.ts
This commit is contained in:
AdisakKanthawilang 2024-11-21 16:01:33 +07:00
commit 2d2f35847a
7 changed files with 73 additions and 37 deletions

View file

@ -2330,6 +2330,11 @@ export class OrganizationController extends Controller {
}; };
} }
const _revision = await this.orgRevisionRepository.findOne({
where: { id: id },
});
if (!_revision) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
const orgRootData = await AppDataSource.getRepository(OrgRoot) const orgRootData = await AppDataSource.getRepository(OrgRoot)
.createQueryBuilder("orgRoot") .createQueryBuilder("orgRoot")
.where("orgRoot.orgRevisionId = :id", { id }) .where("orgRoot.orgRevisionId = :id", { id })
@ -3095,7 +3100,7 @@ export class OrganizationController extends Controller {
}), }),
); );
return new HttpSuccess(formattedData); return new HttpSuccess({ remark: _revision.remark, data: formattedData });
} }
/** /**

View file

@ -1875,8 +1875,8 @@ export class ProfileController extends Controller {
return new HttpSuccess(profile.id); return new HttpSuccess(profile.id);
} }
async sendVerifyEmail( async sendVerifyEmail(
@Request() req:RequestWithUser, @Request() req: RequestWithUser,
@Body() @Body()
body: { body: {
profileId: string; profileId: string;
@ -1890,7 +1890,7 @@ export class ProfileController extends Controller {
const link = process.env.URL + "/verifyemail/" + token; const link = process.env.URL + "/verifyemail/" + token;
// console.log("[link]",link); // console.log("[link]",link);
await new CallAPI() await new CallAPI()
.PostData(req, "/placement/noti/send-mail", { .PostData(req, "/placement/noti/send-mail", {
subject: body.subject, subject: body.subject,
body: link, body: link,
@ -1899,40 +1899,37 @@ export class ProfileController extends Controller {
.catch((error) => { .catch((error) => {
console.error("Error calling API:", error); console.error("Error calling API:", error);
}); });
return new HttpSuccess(); return new HttpSuccess();
} }
/** /**
* API Email * API Email
* *
* @summary Email * @summary Email
* *
*/ */
@Post("verify-email") @Post("verify-email")
async genLinkVerifyEmail( async genLinkVerifyEmail(@Body() body: { token: string }) {
@Body() body:{ const jwt = require("jsonwebtoken");
token: string;
},
) {
const jwt = require('jsonwebtoken');
const secretKey = process.env.AUTH_ACCOUNT_SECRET || "defaultSecretKey"; const secretKey = process.env.AUTH_ACCOUNT_SECRET || "defaultSecretKey";
const decodedToken = jwt.verify(body.token, secretKey); const decodedToken = jwt.verify(body.token, secretKey);
// console.log("[email]",decodedToken); // console.log("[email]",decodedToken);
// console.log("[1]",decodedToken.email_id); // console.log("[1]",decodedToken.email_id);
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where:{ where: {
id: decodedToken.profileId, id: decodedToken.profileId,
email: decodedToken.email_id, email: decodedToken.email_id,
} },
}); });
if(!profile){ throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");} if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
Object.assign(profile, body);
profile.statusEmail = "VERIFIED";
await this.profileRepo.save(profile)
} }
Object.assign(profile, body);
profile.statusEmail = "VERIFIED";
await this.profileRepo.save(profile);
}
/** /**
* API * API
@ -4509,7 +4506,11 @@ export class ProfileController extends Controller {
}, },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); if (request.user.role.includes("SUPER_ADMIN")) {
return new HttpSuccess(null);
} else {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
} }
let orgRevisionPublish: any = await this.orgRevisionRepo let orgRevisionPublish: any = await this.orgRevisionRepo
@ -7984,8 +7985,8 @@ export class ProfileController extends Controller {
profileId: profile.id, profileId: profile.id,
email: body.email, email: body.email,
subject: "ยืนยันอีเมล", subject: "ยืนยันอีเมล",
} };
this.sendVerifyEmail(request,verifyemailBody); this.sendVerifyEmail(request, verifyemailBody);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -1854,7 +1854,11 @@ export class ProfileEmployeeController extends Controller {
}, },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); if (request.user.role.includes("SUPER_ADMIN")) {
return new HttpSuccess(null);
} else {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
} }
let orgRevisionPublish: any = await this.orgRevisionRepo let orgRevisionPublish: any = await this.orgRevisionRepo

View file

@ -1755,7 +1755,11 @@ export class ProfileEmployeeTempController extends Controller {
}, },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); if (request.user.role.includes("SUPER_ADMIN")) {
return new HttpSuccess(null);
} else {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
}
} }
let orgRevisionPublish: any = await this.orgRevisionRepo let orgRevisionPublish: any = await this.orgRevisionRepo

View file

@ -231,6 +231,7 @@ export class KeycloakController extends Controller {
profile.keycloak = null_; profile.keycloak = null_;
profile.roleKeycloaks = []; profile.roleKeycloaks = [];
await this.profileRepo.save(profile); await this.profileRepo.save(profile);
return new HttpSuccess();
} }
} }
// @Security("bearerAuth", ["system", "admin"]) // @Security("bearerAuth", ["system", "admin"])
@ -280,6 +281,7 @@ export class KeycloakController extends Controller {
); );
if (!result) throw new Error("Failed. Cannot set user's role."); if (!result) throw new Error("Failed. Cannot set user's role.");
return new HttpSuccess();
} }
@Delete("{userId}/role/{roleId}") @Delete("{userId}/role/{roleId}")
@ -310,6 +312,7 @@ export class KeycloakController extends Controller {
list.filter((v) => roleId === v.id), list.filter((v) => roleId === v.id),
); );
if (!result) throw new Error("Failed. Cannot remove user's role."); if (!result) throw new Error("Failed. Cannot remove user's role.");
return new HttpSuccess();
} }
/*@Get("user") /*@Get("user")
@ -517,6 +520,7 @@ export class KeycloakController extends Controller {
); );
}), }),
) )
.orderBy("profile.citizenId", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
@ -546,6 +550,7 @@ export class KeycloakController extends Controller {
); );
}), }),
) )
.orderBy("profileEmployee.citizenId", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();

View file

@ -18,8 +18,9 @@ export class OrgRevision extends EntityBase {
orgRevisionName: string; orgRevisionName: string;
@Column({ @Column({
nullable: true,
comment: "หมายเหตุ", comment: "หมายเหตุ",
length: 255, type: "text",
default: null, default: null,
}) })
remark: string; remark: string;

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdataOrgAddRemark11732165078861 implements MigrationInterface {
name = 'UpdataOrgAddRemark11732165078861'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`orgRevision\` DROP COLUMN \`remark\``);
await queryRunner.query(`ALTER TABLE \`orgRevision\` ADD \`remark\` text NULL COMMENT 'หมายเหตุ'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`orgRevision\` DROP COLUMN \`remark\``);
await queryRunner.query(`ALTER TABLE \`orgRevision\` ADD \`remark\` varchar(255) NULL COMMENT 'หมายเหตุ'`);
}
}