feat: fullName search
This commit is contained in:
parent
1b4fbb57c9
commit
f7bde0608a
1 changed files with 71 additions and 1 deletions
|
|
@ -13,6 +13,7 @@ import {
|
|||
Response,
|
||||
Get,
|
||||
Query,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
|
@ -202,12 +203,81 @@ export class ProfileController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Get()
|
||||
@Example({
|
||||
status: 200,
|
||||
message: "สำเร็จ",
|
||||
result: {
|
||||
data: [
|
||||
{
|
||||
id: "ecb0b34c-037e-41f2-b95e-7e19f88b42ae",
|
||||
createdAt: "2024-03-24T12:39:12.105Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-24T12:41:43.164Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "string",
|
||||
prefix: null,
|
||||
firstName: "Methapon",
|
||||
lastName: "Metanipat",
|
||||
citizenId: null,
|
||||
position: null,
|
||||
posLevelId: null,
|
||||
posTypeId: null,
|
||||
email: null,
|
||||
phone: null,
|
||||
keycloak: null,
|
||||
isProbation: false,
|
||||
dateRetire: null,
|
||||
birthDate: null,
|
||||
ethnicity: null,
|
||||
telephoneNumber: null,
|
||||
genderId: "22041841-3149-4b40-ab0e-0d4e98ffd2e1",
|
||||
gender: {
|
||||
id: "22041841-3149-4b40-ab0e-0d4e98ffd2e1",
|
||||
createdAt: "2024-03-24T12:35:45.693Z",
|
||||
createdUserId: "00000000-0000-0000-0000-000000000000",
|
||||
lastUpdatedAt: "2024-03-24T12:35:45.693Z",
|
||||
lastUpdateUserId: "00000000-0000-0000-0000-000000000000",
|
||||
createdFullName: "string",
|
||||
lastUpdateFullName: "string",
|
||||
name: "Male",
|
||||
},
|
||||
relationshipId: null,
|
||||
relationship: null,
|
||||
religionId: null,
|
||||
bloodGroupId: null,
|
||||
bloodGroup: null,
|
||||
posLevel: null,
|
||||
posType: null,
|
||||
},
|
||||
],
|
||||
total: 1,
|
||||
},
|
||||
})
|
||||
async listProfile(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query() searchField?: "firstName" | "lastName" | "citizenId" | "position",
|
||||
@Query() searchField?: "firstName" | "lastName" | "fullName" | "citizenId" | "position",
|
||||
@Query() searchKeyword: string = "",
|
||||
) {
|
||||
if (searchField === "fullName") {
|
||||
const [record, total] = await this.profileRepo
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("profile.posType", "posType")
|
||||
.leftJoinAndSelect("profile.gender", "gender")
|
||||
.leftJoinAndSelect("profile.relationship", "relationship")
|
||||
.leftJoinAndSelect("profile.bloodGroup", "bloodGroup")
|
||||
.where("CONCAT(profile.firstName, ' ', profile.lastName) LIKE :fullName", {
|
||||
fullName: `%${searchKeyword}%`,
|
||||
})
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
|
||||
return new HttpSuccess({ data: record, total });
|
||||
}
|
||||
|
||||
const [record, total] = await this.profileRepo.findAndCount({
|
||||
relations: {
|
||||
posLevel: true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue