Skip to content

Commit

Permalink
Merge pull request #13 from bcgov/api-usage
Browse files Browse the repository at this point in the history
Merge #12 to oracldb branch: Add the api call in frontend to show the usage
  • Loading branch information
MCatherine1994 authored Aug 8, 2022
2 parents 820c53f + ee17cbd commit f64ec22
Show file tree
Hide file tree
Showing 18 changed files with 209 additions and 16,829 deletions.
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

0 comments on commit f64ec22

Please sign in to comment.