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