Skip to content

Commit

Permalink
Merge pull request #207 from kontist/KRP-1227-create-legal-rep
Browse files Browse the repository at this point in the history
KRP-1229 - Legal Representation creation
  • Loading branch information
jablonskipj authored Nov 13, 2024
2 parents 88b8f3b + 314bfd5 commit 0f343e3
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,13 @@ router.post(
safeRequestHandler(businessesAPI.createBeneficialOwner)
);

router.post(
"/businesses/:business_id/legal_representative",
middlewares.withPerson,
middlewares.withBusiness,
safeRequestHandler(businessesAPI.createLegalRepresentative)
);

router.post(
"/businesses/:business_id/identifications",
middlewares.withBusiness,
Expand Down
11 changes: 9 additions & 2 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,20 @@ export enum LegalRepresentativeType {
BUSINESS = "Business",
}

export enum LegalRepresentativeRepresentationType {
ALONE = "ALONE",
JOINT = "JOINT",
OTHER = "OTHER",
AUTHORIZED_PERSON = "AUTHORIZED_PERSON",
}

export type LegalRepresentative = {
id: string;
legal_representative_id: string;
legal_representative_type: LegalRepresentativeType;
valid_until: string;
power_of_attorney_confirmed_at: string;
type_of_representation: string;
type_of_representation: LegalRepresentativeRepresentationType;
business_id: string;
};

Expand Down Expand Up @@ -423,9 +430,9 @@ export type MockBusiness = {
company_status?: string;
createdAt: string;
beneficialOwners?: BeneficialOwner[];
legalRepresentatives?: LegalRepresentative[];
accountOpeningRequests?: AccountOpeningRequest[];
identifications?: BusinessIdentification[];
legalRepresentatives?: LegalRepresentative[];
};

export type MockCreateBusiness = {
Expand Down
1 change: 1 addition & 0 deletions src/routes/business/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./businesses";
export * from "./documents";
export * from "./beneficialOwner";
export * from "./legalRepresentative";
export * from "./identification";
export * from "./complianceQuestions";
49 changes: 49 additions & 0 deletions src/routes/business/legalRepresentative.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { Response } from "express";

import generateID from "../../helpers/id";
import { saveBusiness } from "../../db";
import uuid from "node-uuid";
import {
LegalRepresentative,
LegalRepresentativeType,
LegalRepresentativeRepresentationType,
} from "../../helpers/types";
import { RequestWithBusiness } from "../../helpers/middlewares";

export const createLegalRepresentative = async (
req: RequestWithBusiness,
res: Response
) => {
const { business } = req;

try {
const legalRepresentative: LegalRepresentative = {
id: generateID(),
legal_representative_id: req.body.person_id,
business_id: business.id,
valid_until: null,
legal_representative_type: LegalRepresentativeType.PERSON,
power_of_attorney_confirmed_at: req.body.power_of_attorney_confirmed_at,
type_of_representation: LegalRepresentativeRepresentationType.ALONE,
};

if (!business.legalRepresentatives) {
business.legalRepresentatives = [{ ...legalRepresentative }];
} else {
business.legalRepresentatives.push({ ...legalRepresentative });
}

await saveBusiness(business);

return res.status(201).send(legalRepresentative);
} catch (error) {
return res.status(500).send({
errors: [
{
id: uuid.v4(),
status: 500,
},
],
});
}
};
62 changes: 62 additions & 0 deletions tests/routes/business/legalRepresentative.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { expect } from "chai";
import sinon from "sinon";
import { mockReq, mockRes } from "sinon-express-mock";
import * as db from "../../../src/db";

import * as businessesAPI from "../../../src/routes/business/businesses";
import { createLegalRepresentative } from "../../../src/routes/business/legalRepresentative";

describe("createLegalRepresentative", () => {
let res: sinon.SinonSpy;

describe("when business is found", () => {
let businessId: string;
let req;

before(async () => {
await db.flushDb();
res = mockRes();

await businessesAPI.createBusiness(
{
body: {
name: "Kontist GmbH",
},
headers: {},
},
res
);

businessId = res.send.args[0][0].id;

res = mockRes();
req = mockReq({
params: {
business_id: businessId,
},
body: {
person_id: "1234abcdef",
},
business: {
id: businessId,
},
});
await createLegalRepresentative(req, res);
});

it("should return created legal representative", () => {
const lastCall = res.send.args[res.send.args.length - 1];
expect(lastCall[0].business_id).to.equal(businessId);
expect(lastCall[0].legal_representative_id).to.equal(req.body.person_id);
});

it("should add legal representative to business", async () => {
const business = await db.getBusiness(businessId);
expect(business.legalRepresentatives.length).to.equal(1);
expect(business.legalRepresentatives[0].business_id).to.equal(businessId);
expect(business.legalRepresentatives[0].legal_representative_id).to.equal(
req.body.person_id
);
});
});
});

0 comments on commit 0f343e3

Please sign in to comment.