ปรับเพิ่ม api คำร้องขอแก้ไขข้อมูล
This commit is contained in:
parent
92c6c01438
commit
df0aa633db
3 changed files with 139 additions and 13 deletions
|
|
@ -23,7 +23,7 @@ import {
|
|||
} from "../entities/ProfileEdit";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { IsNull, Not } from "typeorm";
|
||||
import { IsNull, Not, Brackets } from "typeorm";
|
||||
|
||||
@Route("api/v1/org/profile-employee/edit")
|
||||
@Tags("ProfileEmployeeEdit")
|
||||
|
|
@ -38,6 +38,7 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword: string = "",
|
||||
@Query("status") status: string = "",
|
||||
) {
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub });
|
||||
if (!profile) {
|
||||
|
|
@ -46,10 +47,33 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
|
||||
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
|
||||
.createQueryBuilder("ProfileEdit")
|
||||
.leftJoinAndSelect("ProfileEdit.profileEmployeeId", "profileEmployeeId")
|
||||
.where({
|
||||
profileEmployeeId: profile.id,
|
||||
.leftJoinAndSelect("ProfileEdit.profileEmployee", "profileEmployee")
|
||||
.where((qb) => {
|
||||
if (status != "" && status != null) {
|
||||
qb.andWhere("ProfileEdit.status = :status", { status: status });
|
||||
}
|
||||
qb.andWhere("ProfileEdit.profileEmployeeId = :profileEmployeeId", { profileEmployeeId: profile.id });
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != "" && keyword != null
|
||||
? "ProfileEdit.topic LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != "" && keyword != null
|
||||
? "ProfileEdit.detail LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
}),
|
||||
)
|
||||
.orderBy("ProfileEdit.createdAt", "ASC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
|
|
@ -81,13 +105,37 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword: string = "",
|
||||
@Query("status") status: string = "",
|
||||
) {
|
||||
let [getProfileEdit, total] = await AppDataSource.getRepository(ProfileEdit)
|
||||
.createQueryBuilder("ProfileEdit")
|
||||
.leftJoinAndSelect("ProfileEdit.profileEmployee", "profileEmployee")
|
||||
.where({
|
||||
profileEmployeeId: Not(IsNull()),
|
||||
.where((qb) => {
|
||||
if (status != "" && status != null) {
|
||||
qb.andWhere("ProfileEdit.status = :status", { status: status });
|
||||
}
|
||||
qb.andWhere("ProfileEdit.profileEmployeeId IS NOT NULL");
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != "" && keyword != null
|
||||
? "ProfileEdit.topic LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != "" && keyword != null
|
||||
? "ProfileEdit.detail LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
}),
|
||||
)
|
||||
.orderBy("ProfileEdit.createdAt", "ASC")
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
|
|
@ -113,6 +161,17 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
return new HttpSuccess({ data: _data, total: total });
|
||||
}
|
||||
|
||||
@Get("{Id}")
|
||||
public async detailProfileByIdEdit(@Path() Id: string) {
|
||||
const getProfileEdit = await this.profileEditRepository.findOne({
|
||||
where: { id: Id },
|
||||
});
|
||||
if (!getProfileEdit) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
return new HttpSuccess(getProfileEdit);
|
||||
}
|
||||
|
||||
@Get("{profileEmployeeId}")
|
||||
public async detailProfileEdit(@Path() profileEmployeeId: string) {
|
||||
const getProfileEdit = await this.profileEditRepository.findOne({
|
||||
|
|
@ -172,7 +231,10 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
@Request() req: RequestWithUser,
|
||||
@Path() editId: string,
|
||||
) {
|
||||
const record = await this.profileEditRepository.findOneBy({ id: editId });
|
||||
// const record = await this.profileEditRepository.findOneBy({ id: editId });
|
||||
const record = await this.profileEditRepository.findOne({
|
||||
where: { id: editId }
|
||||
});
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
Object.assign(record, requestBody);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue