client management 4 more api
This commit is contained in:
parent
cedbee4ab4
commit
e658df4926
@ -1,4 +1,4 @@
|
|||||||
GET http://localhost:3000/oracle/GetHolderRecord/d/d
|
GET http://localhost:3000/oracle/GetPreparerByClientid?p_spid=as&p_clientid=8
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
|
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||||
import { ManageClientsService } from './manage-clients.service';
|
import { ManageClientsService } from './manage-clients.service';
|
||||||
import { CreateClientDataDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO } from './manage-clients.dto';
|
import { CreateAdditionalClientContactsDTO, CreateAdditionalClientLocationsDTO, CreateClientDataDTO, GetPreparerByClientidDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from './manage-clients.dto';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('oracle')
|
@Controller('oracle')
|
||||||
@ -15,27 +15,33 @@ export class ManageClientsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags('Manage Clients - Oracle')
|
@ApiTags('Manage Clients - Oracle')
|
||||||
@Post('UpdateClient')
|
@Put('UpdateClient')
|
||||||
async UpdateClient(@Body() body:UpdateClientDTO){
|
async UpdateClient(@Body() body:UpdateClientDTO){
|
||||||
return this.manageClientsService.UpdateClient(body);
|
return this.manageClientsService.UpdateClient(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags('Manage Clients - Oracle')
|
@ApiTags('Manage Clients - Oracle')
|
||||||
@Post('UpdateClientContacts')
|
@Put('UpdateClientContacts')
|
||||||
UpdateClientContacts(@Body() body:UpdateClientContactsDTO){
|
UpdateClientContacts(@Body() body:UpdateClientContactsDTO){
|
||||||
return this.manageClientsService.UpdateClientContacts(body);
|
return this.manageClientsService.UpdateClientContacts(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateClientLocations(){
|
@ApiTags('Manage Clients - Oracle')
|
||||||
|
@Put('UpdateClientLocations')
|
||||||
|
UpdateClientLocations(@Body() body:UpdateClientLocationsDTO){
|
||||||
|
return this.manageClientsService.UpdateClientLocations(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateClientContact(){
|
@ApiTags('Manage Clients - Oracle')
|
||||||
|
@Post('CreateAdditionalClientContacts')
|
||||||
|
CreateClientContact(@Body() body:CreateAdditionalClientContactsDTO){
|
||||||
|
return this.manageClientsService.CreateClientContact(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateClientLocation(){
|
@ApiTags('Manage Clients - Oracle')
|
||||||
|
@Post('CreateAdditionalClientLocations')
|
||||||
|
CreateClientLocation(@Body() body:CreateAdditionalClientLocationsDTO){
|
||||||
|
return this.manageClientsService.CreateClientLocation(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags('Manage Clients - Oracle')
|
@ApiTags('Manage Clients - Oracle')
|
||||||
@ -44,8 +50,10 @@ export class ManageClientsController {
|
|||||||
return await this.manageClientsService.GetPreparers(query)
|
return await this.manageClientsService.GetPreparers(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPreparerByClientid(){
|
@ApiTags('Manage Clients - Oracle')
|
||||||
|
@Get('GetPreparerByClientid')
|
||||||
|
GetPreparerByClientid(@Query() body:GetPreparerByClientidDTO){
|
||||||
|
return this.manageClientsService.GetPreparerByClientid(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPreparerContactsByClientid(){
|
GetPreparerContactsByClientid(){
|
||||||
|
|||||||
@ -326,4 +326,164 @@ export class GetPreparersDTO {
|
|||||||
@IsString({ message: "Property p_status must be a string" })
|
@IsString({ message: "Property p_status must be a string" })
|
||||||
@IsDefined({ message: "Property p_status is required" })
|
@IsDefined({ message: "Property p_status is required" })
|
||||||
p_status: string;
|
p_status: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class UpdateClientLocationsDTO {
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Max(999999999, { message: "Property p_spid must not exceed 999999999" })
|
||||||
|
@Min(0, { message: "Property p_spid must be at least 0 or more" })
|
||||||
|
@IsInt({ message: "Property p_spid allows only whole numbers" })
|
||||||
|
@IsNumber({}, { message: "Property p_spid must be a number" })
|
||||||
|
@IsDefined({ message: "Property p_spid is required" })
|
||||||
|
p_spid: number;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Max(999999999, { message: "Property p_clientlocationid must not exceed 999999999" })
|
||||||
|
@Min(0, { message: "Property p_clientlocationid must be at least 0 or more" })
|
||||||
|
@IsInt({ message: "Property p_clientlocationid allows only whole numbers" })
|
||||||
|
@IsNumber({}, { message: "Property p_clientlocationid must be a number" })
|
||||||
|
@IsDefined({ message: "Property p_clientlocationid is required" })
|
||||||
|
p_clientlocationid: number;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 50, { message: "Property p_lcoationname must be between 0 to 50 characters" })
|
||||||
|
@IsString({ message: "Property p_lcoationname must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_lcoationname is required" })
|
||||||
|
p_lcoationname: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 50, { message: "Property p_address1 must be between 0 to 50 characters" })
|
||||||
|
@IsString({ message: "Property p_address1 must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_address1 is required" })
|
||||||
|
p_address1: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
@Length(0, 50, { message: "Property p_address2 must be between 0 to 50 characters" })
|
||||||
|
@IsString({ message: "Property p_address2 must be a string" })
|
||||||
|
@IsOptional()
|
||||||
|
p_address2?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
@Length(0, 30, { message: "Property p_city must be between 0 to 30 characters" })
|
||||||
|
@IsString({ message: "Property p_city must be a string" })
|
||||||
|
@IsOptional()
|
||||||
|
p_city?: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 2, { message: "Property p_state must be between 0 to 2 characters" })
|
||||||
|
@IsString({ message: "Property p_state must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_state is required" })
|
||||||
|
p_state: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 10, { message: "Property p_zip must be between 0 to 10 characters" })
|
||||||
|
@IsString({ message: "Property p_zip must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_zip is required" })
|
||||||
|
p_zip: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 2, { message: "Property p_country must be between 0 to 2 characters" })
|
||||||
|
@IsString({ message: "Property p_country must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_country is required" })
|
||||||
|
p_country: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" })
|
||||||
|
@IsString({ message: "Property p_userid must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_userid is required" })
|
||||||
|
p_userid: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateAdditionalClientContactsDTO {
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Max(999999999, { message: "Property p_spid must not exceed 999999999" })
|
||||||
|
@Min(0, { message: "Property p_spid must be at least 0 or more" })
|
||||||
|
@IsInt({ message: "Property p_spid allows only whole numbers" })
|
||||||
|
@IsNumber({}, { message: "Property p_spid must be a number" })
|
||||||
|
@IsDefined({ message: "Property p_spid is required" })
|
||||||
|
p_spid: number;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Max(999999999, { message: "Property p_clientid must not exceed 999999999" })
|
||||||
|
@Min(0, { message: "Property p_clientid must be at least 0 or more" })
|
||||||
|
@IsInt({ message: "Property p_clientid allows only whole numbers" })
|
||||||
|
@IsNumber({}, { message: "Property p_clientid must be a number" })
|
||||||
|
@IsDefined({ message: "Property p_clientid is required" })
|
||||||
|
p_clientid: number;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true, type: () => [p_contactstableDTO] })
|
||||||
|
@Type(() => p_contactstableDTO)
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@IsArray({ message: "Property p_contactstable allows only array type" })
|
||||||
|
@IsDefined({ message: "Property p_contactstable is required" })
|
||||||
|
p_contactstable: p_contactstableDTO[];
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 1, { message: "Property p_defcontactflag must be exactly 1 character" })
|
||||||
|
@IsString({ message: "Property p_defcontactflag must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_defcontactflag is required" })
|
||||||
|
p_defcontactflag: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" })
|
||||||
|
@IsString({ message: "Property p_userid must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_userid is required" })
|
||||||
|
p_userid: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateAdditionalClientLocationsDTO {
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Max(999999999, { message: "Property p_spid must not exceed 999999999" })
|
||||||
|
@Min(0, { message: "Property p_spid must be at least 0 or more" })
|
||||||
|
@IsInt({ message: "Property p_spid allows only whole numbers" })
|
||||||
|
@IsNumber({}, { message: "Property p_spid must be a number" })
|
||||||
|
@IsDefined({ message: "Property p_spid is required" })
|
||||||
|
p_spid: number;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Max(999999999, { message: "Property p_clientid must not exceed 999999999" })
|
||||||
|
@Min(0, { message: "Property p_clientid must be at least 0 or more" })
|
||||||
|
@IsInt({ message: "Property p_clientid allows only whole numbers" })
|
||||||
|
@IsNumber({}, { message: "Property p_clientid must be a number" })
|
||||||
|
@IsDefined({ message: "Property p_clientid is required" })
|
||||||
|
p_clientid: number;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true, type: () => [p_clientlocaddresstableDTO] })
|
||||||
|
@Type(() => p_clientlocaddresstableDTO)
|
||||||
|
@ValidateNested({ each: true })
|
||||||
|
@IsArray({ message: "Property p_clientlocaddresstable allows only array type" })
|
||||||
|
@IsDefined({ message: "Property p_clientlocaddresstable is required" })
|
||||||
|
p_clientlocaddresstable: p_clientlocaddresstableDTO[];
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 1, { message: "Property p_defcontactflag must be exactly 1 character" })
|
||||||
|
@IsString({ message: "Property p_defcontactflag must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_defcontactflag is required" })
|
||||||
|
p_defcontactflag: string;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Length(0, 100, { message: "Property p_userid must be between 0 to 100 characters" })
|
||||||
|
@IsString({ message: "Property p_userid must be a string" })
|
||||||
|
@IsDefined({ message: "Property p_userid is required" })
|
||||||
|
p_userid: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GetPreparerByClientidDTO {
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Transform(({ value }) => Number(value))
|
||||||
|
@Max(999999999, { message: "Property p_spid must not exceed 999999999" })
|
||||||
|
@Min(0, { message: "Property p_spid must be at least 0 or more" })
|
||||||
|
@IsInt({ message: "Property p_spid allows only whole numbers" })
|
||||||
|
@IsNumber({}, { message: "Property p_spid must be a number" })
|
||||||
|
@IsDefined({ message: "Property p_spid is required" })
|
||||||
|
p_spid: number;
|
||||||
|
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
@Transform(({ value }) => Number(value))
|
||||||
|
@Max(999999999, { message: "Property p_clientid must not exceed 999999999" })
|
||||||
|
@Min(0, { message: "Property p_clientid must be at least 0 or more" })
|
||||||
|
@IsInt({ message: "Property p_clientid allows only whole numbers" })
|
||||||
|
@IsNumber({}, { message: "Property p_clientid must be a number" })
|
||||||
|
@IsDefined({ message: "Property p_clientid is required" })
|
||||||
|
p_clientid: number;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { OracleDBService } from 'src/db/db.service';
|
import { OracleDBService } from 'src/db/db.service';
|
||||||
import { CreateClientDataDTO, GetPreparersDTO, p_clientlocaddresstableDTO, UpdateClientContactsDTO, UpdateClientDTO } from './manage-clients.dto';
|
import { CreateAdditionalClientContactsDTO, CreateAdditionalClientLocationsDTO, CreateClientDataDTO, GetPreparerByClientidDTO, GetPreparersDTO, p_clientlocaddresstableDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from './manage-clients.dto';
|
||||||
import { p_contactstableDTO } from '../manage-holders/manage-holders.dto';
|
import { p_contactstableDTO } from '../manage-holders/manage-holders.dto';
|
||||||
import * as oracledb from 'oracledb'
|
import * as oracledb from 'oracledb'
|
||||||
|
|
||||||
@ -547,16 +547,397 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateClientLocations = async () => {
|
UpdateClientLocations = async (body: UpdateClientLocationsDTO) => {
|
||||||
|
|
||||||
|
let newBody = {
|
||||||
|
"p_spid": null,
|
||||||
|
"p_clientlocationid": null,
|
||||||
|
"p_lcoationname": null,
|
||||||
|
"p_address1": null,
|
||||||
|
"p_address2": null,
|
||||||
|
"p_city": null,
|
||||||
|
"p_state": null,
|
||||||
|
"p_zip": null,
|
||||||
|
"p_country": null,
|
||||||
|
"p_userid": null
|
||||||
|
}
|
||||||
|
|
||||||
|
let reqBody = JSON.parse(JSON.stringify(body));
|
||||||
|
|
||||||
|
function setEmptyStringsToNull(obj) {
|
||||||
|
Object.keys(obj).forEach(key => {
|
||||||
|
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
||||||
|
setEmptyStringsToNull(obj[key]);
|
||||||
|
} else if (obj[key] === "") {
|
||||||
|
obj[key] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setEmptyStringsToNull(reqBody);
|
||||||
|
|
||||||
|
const finalBody: UpdateClientLocationsDTO = { ...newBody, ...reqBody };
|
||||||
|
|
||||||
|
let connection;
|
||||||
|
let p_cursor_rows = [];
|
||||||
|
try {
|
||||||
|
|
||||||
|
connection = await this.oracleDBService.getConnection()
|
||||||
|
if (!connection) {
|
||||||
|
throw new Error('No DB Connected')
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await connection.execute(
|
||||||
|
`BEGIN
|
||||||
|
MANAGEPREPARER_PKG.UpdateClientLocations(
|
||||||
|
:p_spid,
|
||||||
|
:p_clientlocationid,
|
||||||
|
:p_lcoationname,
|
||||||
|
:p_address1,
|
||||||
|
:p_address2,
|
||||||
|
:p_city,
|
||||||
|
:p_state,
|
||||||
|
:p_zip,
|
||||||
|
:p_country,
|
||||||
|
:p_userid,
|
||||||
|
:p_cursor
|
||||||
|
);
|
||||||
|
END;`,
|
||||||
|
{
|
||||||
|
p_spid: {
|
||||||
|
val: finalBody.p_spid ? finalBody.p_spid : null,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER
|
||||||
|
},
|
||||||
|
p_clientlocationid: {
|
||||||
|
val: finalBody.p_clientlocationid ? finalBody.p_clientlocationid : null,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER
|
||||||
|
},
|
||||||
|
p_lcoationname: {
|
||||||
|
val: finalBody.p_lcoationname ? finalBody.p_lcoationname : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_address1: {
|
||||||
|
val: finalBody.p_address1 ? finalBody.p_address1 : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_address2: {
|
||||||
|
val: finalBody.p_address2 ? finalBody.p_address2 : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_city: {
|
||||||
|
val: finalBody.p_city ? finalBody.p_city : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_state: {
|
||||||
|
val: finalBody.p_state ? finalBody.p_state : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_zip: {
|
||||||
|
val: finalBody.p_zip ? finalBody.p_zip : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_country: {
|
||||||
|
val: finalBody.p_country ? finalBody.p_country : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_userid: {
|
||||||
|
val: finalBody.p_userid ? finalBody.p_userid : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_cursor: {
|
||||||
|
type: oracledb.CURSOR,
|
||||||
|
dir: oracledb.BIND_OUT
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
outFormat: oracledb.OUT_FORMAT_OBJECT
|
||||||
|
}
|
||||||
|
);
|
||||||
|
await connection.commit();
|
||||||
|
|
||||||
|
if (result.outBinds && result.outBinds.p_cursor) {
|
||||||
|
const cursor = result.outBinds.p_cursor;
|
||||||
|
let rowsBatch;
|
||||||
|
|
||||||
|
do {
|
||||||
|
rowsBatch = await cursor.getRows(100);
|
||||||
|
p_cursor_rows = p_cursor_rows.concat(rowsBatch);
|
||||||
|
} while (rowsBatch.length > 0);
|
||||||
|
|
||||||
|
|
||||||
|
await cursor.close();
|
||||||
|
} else {
|
||||||
|
throw new Error('No cursor returned from the stored procedure');
|
||||||
|
}
|
||||||
|
|
||||||
|
return { p_cursor: p_cursor_rows };
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching users: ', err);
|
||||||
|
return { error: err.message }
|
||||||
|
} finally { }
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateClientContact = async () => {
|
CreateClientContact = async (body: CreateAdditionalClientContactsDTO) => {
|
||||||
|
|
||||||
|
let newBody = {
|
||||||
|
"p_spid": null,
|
||||||
|
"p_clientid": null,
|
||||||
|
"p_contactstable": null,
|
||||||
|
"p_defcontactflag": null,
|
||||||
|
"p_userid": null
|
||||||
|
}
|
||||||
|
|
||||||
|
let reqBody = JSON.parse(JSON.stringify(body));
|
||||||
|
|
||||||
|
function setEmptyStringsToNull(obj) {
|
||||||
|
Object.keys(obj).forEach(key => {
|
||||||
|
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
||||||
|
setEmptyStringsToNull(obj[key]);
|
||||||
|
} else if (obj[key] === "") {
|
||||||
|
obj[key] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setEmptyStringsToNull(reqBody);
|
||||||
|
|
||||||
|
const finalBody: CreateAdditionalClientContactsDTO = { ...newBody, ...reqBody };
|
||||||
|
|
||||||
|
let connection;
|
||||||
|
let p_cursor_rows = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
connection = await this.oracleDBService.getConnection()
|
||||||
|
if (!connection) {
|
||||||
|
throw new Error('No DB Connected')
|
||||||
|
}
|
||||||
|
|
||||||
|
const CONTACTSTABLE = await connection.getDbObjectClass('CARNETSYS.CONTACTSTABLE');
|
||||||
|
|
||||||
|
// Check if CONTACTSTABLE is a constructor
|
||||||
|
if (typeof CONTACTSTABLE !== 'function') {
|
||||||
|
throw new Error('CONTACTSTABLE is not a constructor');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function CREATECONTACTSTABLE_INSTANCE(connection, FirstName, LastName, MiddleInitial, Title, EmailAddress, PhoneNo, MobileNo, FaxNo) {
|
||||||
|
const result = await connection.execute(
|
||||||
|
`SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`,
|
||||||
|
{
|
||||||
|
FirstName,
|
||||||
|
LastName,
|
||||||
|
MiddleInitial,
|
||||||
|
Title,
|
||||||
|
EmailAddress,
|
||||||
|
PhoneNo,
|
||||||
|
MobileNo,
|
||||||
|
FaxNo
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return result.rows[0][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const CONTACTSARRAY = finalBody.p_contactstable ? await Promise.all(finalBody.p_contactstable.map(async (x: p_contactstableDTO) => {
|
||||||
|
return await CREATECONTACTSTABLE_INSTANCE(connection, x.FirstName, x.LastName, x.MiddleInitial, x.Title, x.EmailAddress, x.PhoneNo, x.MobileNo, x.FaxNo);
|
||||||
|
})) : [];
|
||||||
|
|
||||||
|
// Create an instance of GLTABLE
|
||||||
|
const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY);
|
||||||
|
|
||||||
|
const result = await connection.execute(
|
||||||
|
`BEGIN
|
||||||
|
MANAGEPREPARER_PKG.CreateClientContact(
|
||||||
|
:p_spid,
|
||||||
|
:p_clientid,
|
||||||
|
:p_contactstable,
|
||||||
|
:p_defcontactflag,
|
||||||
|
:p_userid,
|
||||||
|
:p_cursor
|
||||||
|
);
|
||||||
|
END;`,
|
||||||
|
{
|
||||||
|
p_spid: {
|
||||||
|
val: finalBody.p_spid ? finalBody.p_spid : null,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER
|
||||||
|
},
|
||||||
|
p_clientid: {
|
||||||
|
val: finalBody.p_clientid ? finalBody.p_clientid : null,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER
|
||||||
|
},
|
||||||
|
p_contactstable: {
|
||||||
|
val: CONTACTSTABLE_INSTANCE,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_defcontactflag: {
|
||||||
|
val: finalBody.p_defcontactflag ? finalBody.p_defcontactflag : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_userid: {
|
||||||
|
val: finalBody.p_userid ? finalBody.p_userid : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_cursor: {
|
||||||
|
type: oracledb.CURSOR,
|
||||||
|
dir: oracledb.BIND_OUT
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
outFormat: oracledb.OUT_FORMAT_OBJECT
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await connection.commit();
|
||||||
|
|
||||||
|
if (result.outBinds && result.outBinds.p_cursor) {
|
||||||
|
const cursor = result.outBinds.p_cursor;
|
||||||
|
let rowsBatch;
|
||||||
|
|
||||||
|
do {
|
||||||
|
rowsBatch = await cursor.getRows(100);
|
||||||
|
p_cursor_rows = p_cursor_rows.concat(rowsBatch);
|
||||||
|
} while (rowsBatch.length > 0);
|
||||||
|
|
||||||
|
|
||||||
|
await cursor.close();
|
||||||
|
} else {
|
||||||
|
throw new Error('No cursor returned from the stored procedure');
|
||||||
|
}
|
||||||
|
|
||||||
|
return { p_cursor: p_cursor_rows };
|
||||||
|
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching users: ', err);
|
||||||
|
return { error: err.message }
|
||||||
|
} finally { }
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateClientLocation = async () => {
|
CreateClientLocation = async (body: CreateAdditionalClientLocationsDTO) => {
|
||||||
|
let newBody = {
|
||||||
|
"p_spid": null,
|
||||||
|
"p_clientid": null,
|
||||||
|
"p_clientlocaddresstable": null,
|
||||||
|
"p_defcontactflag": null,
|
||||||
|
"p_userid": null
|
||||||
|
}
|
||||||
|
|
||||||
|
let reqBody = JSON.parse(JSON.stringify(body));
|
||||||
|
|
||||||
|
function setEmptyStringsToNull(obj) {
|
||||||
|
Object.keys(obj).forEach(key => {
|
||||||
|
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
||||||
|
setEmptyStringsToNull(obj[key]);
|
||||||
|
} else if (obj[key] === "") {
|
||||||
|
obj[key] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setEmptyStringsToNull(reqBody);
|
||||||
|
|
||||||
|
const finalBody: CreateAdditionalClientLocationsDTO = { ...newBody, ...reqBody };
|
||||||
|
|
||||||
|
let connection;
|
||||||
|
let p_cursor_rows = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
connection = await this.oracleDBService.getConnection()
|
||||||
|
if (!connection) {
|
||||||
|
throw new Error('No DB Connected')
|
||||||
|
}
|
||||||
|
|
||||||
|
const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSTABLE');
|
||||||
|
|
||||||
|
if (typeof CLIENTLOCADDRESSTABLE !== 'function') {
|
||||||
|
throw new Error('CLIENTLOCADDRESSTABLE is not a constructor');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function CREATECLIENTLOCADDRESSTABLE_INSTANCE(connection, Nameof, Address1, Address2, City, State, Zip, Country) {
|
||||||
|
const result = await connection.execute(
|
||||||
|
`SELECT CARNETSYS.CLIENTLOCADDRESSARRAY(:Nameof, :Address1, :Address2, :City, :State, :Zip, :Country) FROM dual`,
|
||||||
|
{
|
||||||
|
Nameof,
|
||||||
|
Address1,
|
||||||
|
Address2,
|
||||||
|
City,
|
||||||
|
State,
|
||||||
|
Zip,
|
||||||
|
Country
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return result.rows[0][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const CLIENTLOCADDRESSARRAY = finalBody.p_clientlocaddresstable ? await Promise.all(finalBody.p_clientlocaddresstable.map(async (x: p_clientlocaddresstableDTO) => {
|
||||||
|
return await CREATECLIENTLOCADDRESSTABLE_INSTANCE(connection, x.Nameof, x.Address1, x.Address2, x.City, x.State, x.Zip, x.Country);
|
||||||
|
})) : [];
|
||||||
|
|
||||||
|
const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE(CLIENTLOCADDRESSARRAY);
|
||||||
|
|
||||||
|
const result = await connection.execute(
|
||||||
|
`BEGIN
|
||||||
|
MANAGEPREPARER_PKG.CreateClientLocation(
|
||||||
|
:p_spid,
|
||||||
|
:p_clientid,
|
||||||
|
:p_clientlocaddresstable,
|
||||||
|
:p_defcontactflag,
|
||||||
|
:p_userid
|
||||||
|
);
|
||||||
|
END;`,
|
||||||
|
{
|
||||||
|
p_spid: {
|
||||||
|
val: finalBody.p_spid ? finalBody.p_spid : null,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER
|
||||||
|
},
|
||||||
|
p_clientid: {
|
||||||
|
val: finalBody.p_clientid ? finalBody.p_clientid : null,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER
|
||||||
|
},
|
||||||
|
p_clientlocaddresstable: {
|
||||||
|
val: CLIENTLOCADDRESSTABLE_INSTANCE,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_defcontactflag: {
|
||||||
|
val: finalBody.p_defcontactflag ? finalBody.p_defcontactflag : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_userid: {
|
||||||
|
val: finalBody.p_userid ? finalBody.p_userid : null,
|
||||||
|
type: oracledb.DB_TYPE_NVARCHAR
|
||||||
|
},
|
||||||
|
p_cursor: {
|
||||||
|
type: oracledb.CURSOR,
|
||||||
|
dir: oracledb.BIND_OUT
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
outFormat: oracledb.OUT_FORMAT_OBJECT
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await connection.commit();
|
||||||
|
|
||||||
|
if (result.outBinds && result.outBinds.p_cursor) {
|
||||||
|
const cursor = result.outBinds.p_cursor;
|
||||||
|
let rowsBatch;
|
||||||
|
|
||||||
|
do {
|
||||||
|
rowsBatch = await cursor.getRows(100);
|
||||||
|
p_cursor_rows = p_cursor_rows.concat(rowsBatch);
|
||||||
|
} while (rowsBatch.length > 0);
|
||||||
|
|
||||||
|
|
||||||
|
await cursor.close();
|
||||||
|
} else {
|
||||||
|
throw new Error('No cursor returned from the stored procedure');
|
||||||
|
}
|
||||||
|
|
||||||
|
return { p_cursor: p_cursor_rows };
|
||||||
|
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching users: ', err);
|
||||||
|
return { error: err.message }
|
||||||
|
} finally { }
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPreparers = async (body: GetPreparersDTO) => {
|
GetPreparers = async (body: GetPreparersDTO) => {
|
||||||
@ -675,7 +1056,63 @@ export class ManageClientsService {
|
|||||||
} finally { }
|
} finally { }
|
||||||
}
|
}
|
||||||
|
|
||||||
GetPreparerByClientid = async () => {
|
GetPreparerByClientid = async (body: GetPreparerByClientidDTO) => {
|
||||||
|
|
||||||
|
let connection;
|
||||||
|
let p_cursor_rows = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection = await this.oracleDBService.getConnection()
|
||||||
|
if (!connection) {
|
||||||
|
throw new Error('No DB Connected')
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await connection.execute(
|
||||||
|
`BEGIN
|
||||||
|
MANAGEPREPARER_PKG.GetPreparerByClientid(
|
||||||
|
:p_spid,
|
||||||
|
:p_clientid,
|
||||||
|
:p_cursor
|
||||||
|
);
|
||||||
|
END;`,
|
||||||
|
{
|
||||||
|
p_spid: {
|
||||||
|
val: body.p_spid,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER,
|
||||||
|
},
|
||||||
|
p_clientid: {
|
||||||
|
val: body.p_clientid,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER,
|
||||||
|
},
|
||||||
|
p_cursor: {
|
||||||
|
type: oracledb.CURSOR,
|
||||||
|
dir: oracledb.BIND_OUT
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
outFormat: oracledb.OUT_FORMAT_OBJECT
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.outBinds && result.outBinds.p_cursor) {
|
||||||
|
const cursor = result.outBinds.p_cursor;
|
||||||
|
let rowsBatch;
|
||||||
|
|
||||||
|
do {
|
||||||
|
rowsBatch = await cursor.getRows(100);
|
||||||
|
p_cursor_rows = p_cursor_rows.concat(rowsBatch);
|
||||||
|
} while (rowsBatch.length > 0);
|
||||||
|
|
||||||
|
|
||||||
|
await cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return { p_cursor: p_cursor_rows };
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching users: ', err);
|
||||||
|
return { error: err.message }
|
||||||
|
} finally { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user