Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge #12 to oracldb branch: Add the api call in frontend to show the usage #13

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions backend/src/clientpublicview/services/clientPublicView.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ClientPublicViewEntity } from '../entities/clientPublicView.entity';
import { ClientPublicView } from "../entities/clientPublicView.interface";
import { ClientPublicView } from '../entities/clientPublicView.interface';

@Injectable()
export class ClientPublicViewService {
Expand All @@ -14,53 +14,58 @@ export class ClientPublicViewService {
// the full non individual client list is too long, currently only set to return 10
findInViewAllNonIndividualClients(): Promise<ClientPublicView[]> {
return this.clientPublicViewRepository
.createQueryBuilder("V_CLIENT_PUBLIC")
.where("V_CLIENT_PUBLIC.CLIENT_TYPE_CODE != :clientTypeCode", {
clientTypeCode: "I",
.createQueryBuilder('V_CLIENT_PUBLIC')
.where('V_CLIENT_PUBLIC.CLIENT_TYPE_CODE != :clientTypeCode', {
clientTypeCode: 'I',
})
.take(10)
.getMany();
}

findInViewBy(clientNumber: string, clientName: string): Promise<ClientPublicView[]> {
let sqlWhereStr = "1 = 1";
findInViewBy(
clientNumber: string,
clientName: string,
): Promise<ClientPublicView[]> {
let sqlWhereStr = '1 = 1';

if (clientNumber) {
sqlWhereStr = sqlWhereStr + " AND C.CLIENT_NUMBER LIKE :clientNumber";
if (clientNumber && clientNumber !== '') {
sqlWhereStr = sqlWhereStr + ' AND C.CLIENT_NUMBER LIKE :clientNumber';
}

if (clientName) {
if (clientName && clientName !== '') {
sqlWhereStr =
sqlWhereStr +
" AND " +
"(LOWER(C.CLIENT_NAME) LIKE LOWER(:clientName) OR " +
" LOWER(C.LEGAL_FIRST_NAME) LIKE LOWER(:clientName) OR " +
" LOWER(C.LEGAL_MIDDLE_NAME) LIKE LOWER(:clientName)" +
")";
' AND ' +
'(LOWER(C.CLIENT_NAME) LIKE LOWER(:clientName) OR ' +
' LOWER(C.LEGAL_FIRST_NAME) LIKE LOWER(:clientName) OR ' +
' LOWER(C.LEGAL_MIDDLE_NAME) LIKE LOWER(:clientName)' +
')';
}

//TODO: Put harcoded values in a different place
return this.clientPublicViewRepository
.createQueryBuilder()
.select("C.CLIENT_NUMBER", "Client Number")
.select('C.CLIENT_NUMBER', 'Client Number')
.addSelect(
"CASE WHEN C.CLIENT_TYPE_CODE = 'I' " +
"THEN C.LEGAL_FIRST_NAME || ' ' || C.LEGAL_MIDDLE_NAME " +
"ELSE C.CLIENT_NAME END",
"Client Name",
"CASE WHEN C.CLIENT_TYPE_CODE = 'I' " +
"THEN C.LEGAL_FIRST_NAME || ' ' || C.LEGAL_MIDDLE_NAME " +
'ELSE C.CLIENT_NAME END',
'Client Name',
)
.addSelect("C.CLIENT_TYPE_CODE", "Client Type Code")
.addSelect('C.CLIENT_TYPE_CODE', 'Client Type Code')
.addSelect(
"CASE WHEN C.CLIENT_STATUS_CODE = 'ACT' " +
"THEN 'true' " +
"ELSE 'false' END", "Client Active")
.from(ClientPublicViewEntity, "C")
"CASE WHEN C.CLIENT_STATUS_CODE = 'ACT' " +
"THEN 'true' " +
"ELSE 'false' END",
'Client Active',
)
.from(ClientPublicViewEntity, 'C')
.where(sqlWhereStr, {
clientNumber: "%" + clientNumber,
clientName: clientName + "%",
clientNumber: '%' + clientNumber,
clientName: clientName + '%',
})
.take(10)
.orderBy("C.LEGAL_FIRST_NAME")
.orderBy('C.LEGAL_FIRST_NAME')
.getRawOne();
}
}
3 changes: 3 additions & 0 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ async function bootstrap() {
if (!origin || whitelist.indexOf(origin) !== -1) {
callback(null, true);
}
// else {
// callback(new Error('Not allowed by CORS'));
// }
},
});

Expand Down
Loading