Skip to content

Commit

Permalink
Add kyc-case service
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Sundberg <[email protected]>
  • Loading branch information
seansund committed Sep 8, 2023
1 parent d816f7e commit 4c5d38d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 54 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"generate-schema": "ts-node scripts/generate-schema.ts",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
Expand Down
54 changes: 23 additions & 31 deletions schema.gql
Original file line number Diff line number Diff line change
@@ -1,58 +1,50 @@
# ------------------------------------------------------
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------

"""Case comment"""
type Comment {
author: String
comment: String!
timestamp: String!
}

"""KYC Customer"""
type Customer {
countryOfResidence: String!
dateOfBirth: String!
name: String!
}

input CustomerInput {
countryOfResidence: String!
dateOfBirth: String!
name: String!
countryOfResidence: String!
}

"""KYC Document"""
type Document {
id: ID!
name: String!
path: String!
}

"""greeting"""
type Greeting {
greeting: String!
"""Case comment"""
type Comment {
id: ID!
comment: String!
timestamp: String!
author: String
}

"""KYC Case"""
type KycCase {
comments: [Comment!]!
id: ID!
status: String!
customer: Customer!
documents: [Document!]!
id: String!
status: String!
comments: [Comment!]!
}

type Query {
listCases: [KycCase!]!
getCase(id: ID!): KycCase!
}

type Mutation {
addDocumentToCase(documentName: String!, documentPath: String!, id: ID!): KycCase!
approveCase(comment: String!, id: ID!): KycCase!
createCase(customer: CustomerInput!): KycCase!
reviewCase(comment: String!, id: ID!): KycCase!
addDocumentToCase(caseId: ID!, documentName: String!, documentPath: String!): KycCase!
reviewCase(caseId: ID!, comment: String, timestamp: String, author: String): KycCase!
approveCase(caseId: ID!, comment: String, timestamp: String, author: String): KycCase!
}

type Query {
getCase(id: ID!): KycCase!
helloWorld: Greeting!
listCases: [KycCase!]!
input CustomerInput {
name: String!
dateOfBirth: String!
countryOfResidence: String!
}

type Subscription {
Expand Down
20 changes: 20 additions & 0 deletions scripts/generate-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {NestFactory} from "@nestjs/core";
import {GraphQLSchemaBuilderModule, GraphQLSchemaFactory} from "@nestjs/graphql";
import {printSchema} from "graphql/utilities";
import {promises} from 'fs';

import {KycCaseResolver} from "../src/resolvers/kyc-case";

const generateSchema = async (file: string) => {
const app = await NestFactory.create(GraphQLSchemaBuilderModule);
await app.init();

const gqlSchemaFactory = app.get(GraphQLSchemaFactory);
const schema = await gqlSchemaFactory.create([KycCaseResolver]);

if (file) {
await promises.writeFile(file, printSchema(schema))
}
}

generateSchema('schema.gql').catch(err => console.error('Unable to generate schema: ', err));
9 changes: 4 additions & 5 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Module } from '@nestjs/common';
import {Module} from '@nestjs/common';
import {GraphQLModule} from "@nestjs/graphql";
import {ApolloDriver, ApolloDriverConfig} from "@nestjs/apollo";
import {join} from 'path';

import { controllers } from './controllers';
import {ServiceModule} from "./services";
import {controllers} from './controllers';
import {ResolverModule} from "./resolvers";
import {ServiceModule} from "./services";

const imports = [
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
autoSchemaFile: 'schema.gql',
sortSchema: true,
subscriptions: {
'graphql-ws': true
'graphql-ws': true,
},
}),
ServiceModule,
Expand Down
8 changes: 6 additions & 2 deletions src/graphql-types/kyc-case.graphql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Field, InputType, ObjectType} from "@nestjs/graphql";
import {Field, ID, InputType, ObjectType} from "@nestjs/graphql";
import {
CommentModel,
CustomerModel,
Expand All @@ -20,6 +20,8 @@ export class Customer implements CustomerModel {

@ObjectType({ description: 'KYC Document' })
export class Document implements DocumentModel {
@Field(() => ID)
id: string;
@Field()
name: string;
@Field()
Expand All @@ -40,6 +42,8 @@ export class CustomerRiskAssessment implements CustomerRiskAssessmentModel {

@ObjectType({description: 'Case comment'})
export class Comment implements CommentModel {
@Field(() => ID)
id: string;
@Field()
comment: string;
@Field()
Expand All @@ -50,7 +54,7 @@ export class Comment implements CommentModel {

@ObjectType({ description: 'KYC Case' })
export class KycCase implements KycCaseModel {
@Field()
@Field(() => ID)
id: string;
@Field()
status: string;
Expand Down
2 changes: 2 additions & 0 deletions src/models/kyc-case.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface KycCaseModel {
}

export interface CommentModel {
id: string;
comment: string;
timestamp: string;
author?: string;
Expand All @@ -21,6 +22,7 @@ export interface CustomerModel {
}

export interface DocumentModel {
id: string;
name: string;
path: string;
}
Expand Down
18 changes: 11 additions & 7 deletions src/resolvers/kyc-case/kyc-case.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class KycCaseResolver {

@Mutation(() => KycCase)
async addDocumentToCase(
@Args('id', { type: () => ID }) caseId: string,
@Args('caseId', { type: () => ID }) caseId: string,
@Args('documentName', { type: () => String }) documentName: string,
@Args('documentPath', { type: () => String }) documentPath: string,
): Promise<KycCaseModel> {
Expand All @@ -51,17 +51,21 @@ export class KycCaseResolver {

@Mutation(() => KycCase)
async reviewCase(
@Args('id', { type: () => ID }) caseId: string,
@Args('comment', { type: () => String }) comment: string
@Args('caseId', { type: () => ID }) caseId: string,
@Args('comment', { type: () => String, nullable: true }) comment?: string,
@Args('timestamp', { type: () => String, nullable: true }) timestamp?: string,
@Args('author', { type: () => String, nullable: true }) author?: string,
): Promise<KycCaseModel> {
return this.service.reviewCase(caseId, comment);
return this.service.reviewCase(caseId, comment, timestamp, author);
}

@Mutation(() => KycCase)
async approveCase(
@Args('id', { type: () => ID }) caseId: string,
@Args('comment', { type: () => String }) comment: string
@Args('caseId', { type: () => ID }) caseId: string,
@Args('comment', { type: () => String, nullable: true }) comment?: string,
@Args('timestamp', { type: () => String, nullable: true }) timestamp?: string,
@Args('author', { type: () => String, nullable: true }) author?: string,
): Promise<KycCaseModel> {
return this.service.approveCase(caseId, comment);
return this.service.approveCase(caseId, comment, timestamp, author);
}
}
25 changes: 16 additions & 9 deletions src/services/kyc-case/kyc-case-management.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ export class KycCaseManagementMock implements KycCaseManagementApi {
return newCase;
}

async addDocumentToCase(id: string, documentName: string, documentPath: string): Promise<KycCaseModel> {
const currentCase = await this.getCase(id);
async addDocumentToCase(caseId: string, documentName: string, documentPath: string): Promise<KycCaseModel> {
const currentCase = await this.getCase(caseId);

currentCase.status = 'Pending';

currentCase.documents.push({name: documentName, path: documentPath});
const id = '' + (currentCase.documents.length + 1);

currentCase.documents.push({id: `${caseId}-${id}`, name: documentName, path: documentPath});

this.subject.next(this.subject.value);

Expand All @@ -85,24 +87,29 @@ export class KycCaseManagementMock implements KycCaseManagementApi {

currentCase.status = 'Pending';

if (comment) {
currentCase.comments.push(Object.assign({comment, timestamp}, author ? {author} : {}))
}
this.addComment(currentCase, comment, timestamp, author);

this.subject.next(this.subject.value);

return currentCase;
}

addComment(currentCase: KycCaseModel, comment?: string, timestamp?: string, author?: string) {
if (comment) {
const caseId = currentCase.id;
const commentId = '' + (currentCase.comments.length + 1)

currentCase.comments.push(Object.assign({id: `${caseId}-${commentId}`, comment, timestamp}, author ? {author} : {}))
}
}

async approveCase(id: string, comment?: string, timestamp: string = new Date().toISOString(), author?: string): Promise<KycCaseModel> {
const currentCase = first(this.subject.value.filter(c => c.id === id))
.orElseThrow(() => new CaseNotFound(id))

currentCase.status = 'Closed';

if (comment) {
currentCase.comments.push(Object.assign({comment, timestamp}, author ? {author} : {}))
}
this.addComment(currentCase, comment, timestamp, author);

this.subject.next(this.subject.value);

Expand Down

0 comments on commit 4c5d38d

Please sign in to comment.