From 7744d7e09869dc22888a9f4618e9e4ea5ddddc7f Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Tue, 3 Oct 2023 10:23:47 +1100 Subject: [PATCH 1/5] update admin account db schema --- backend/src/entity/admin_account.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/entity/admin_account.ts b/backend/src/entity/admin_account.ts index 2fb370cd7..96ddfffd0 100644 --- a/backend/src/entity/admin_account.ts +++ b/backend/src/entity/admin_account.ts @@ -20,6 +20,9 @@ export default class AdminAccount { @Column({ type: 'text', default: 'no token set' }) public latestValidToken: string; + @Column('text', { array: true, default: '{}' }) + public verifiedCompaniesAddresses: string[]; + @CreateDateColumn() createdAt: Date; From f0327e73efd3cfeab9bfa88e15f22a897f16f116 Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Tue, 3 Oct 2023 10:24:07 +1100 Subject: [PATCH 2/5] implement getVerifiedCompaniesAddresses --- backend/src/admin.ts | 40 ++++++++++++++++++++++++++++++++ backend/src/index.ts | 37 ++++++++++++++++++++++++++++++ backend/tests/admin_tests.js | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) diff --git a/backend/src/admin.ts b/backend/src/admin.ts index de61915a3..9e9f9641c 100644 --- a/backend/src/admin.ts +++ b/backend/src/admin.ts @@ -18,6 +18,7 @@ import { AdminApprovedJobPostsRequest, } from './types/request'; import { env } from './environment'; +import AdminAccount from './entity/admin_account'; const LM = new LogModule('ADMIN'); @@ -763,4 +764,43 @@ You job post request titled "${jobToReject.role}" has been rejected as it does n next, ); } + + public static async GetVerifiedCompaniesAddresses( + this: void, + req: GeneralAdminRequest, + res: Response, + next: NextFunction, + ) { + await Helpers.catchAndLogError( + res, + async (): Promise => { + const { adminID } = req; + Helpers.requireParameters(adminID); + + Logger.Info(LM, `ADMIN=${adminID} attempting to get verified companies email addresses`); + + // Trying to select verifiedCompaniesAddresses returns an object rather than the array... + const adminAccount = await Helpers.doSuccessfullyOrFail( + async () => AppDataSource.getRepository(AdminAccount) + .createQueryBuilder() + // .select('AdminAccount.verifiedCompaniesAddresses') + .where('AdminAccount.id = :id', { id: adminID }) + .getOne(), + 'Failed to retrieve verified companies email addresses', + ); + + Logger.Info(LM, `ADMIN=${adminID} successfully retrieved verified companies email addresses`); + + return { + status: StatusCodes.OK, + msg: { verifiedCompaniesAddresses: adminAccount.verifiedCompaniesAddresses }, + }; + }, + () => ({ + status: StatusCodes.BAD_REQUEST, + msg: undefined, + }), + next, + ); + } } diff --git a/backend/src/index.ts b/backend/src/index.ts index 0dfa88ae1..32bb24ab2 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -518,6 +518,43 @@ app.put( Middleware.genericLoggingMiddleware, ); +app.get( + '/admin/verified-companies-addresses', + cors(corsOptions), + Middleware.authoriseAdminMiddleware, + (req: GeneralAdminRequest, res, next) => { + (async () => { + await AdminFunctions.GetVerifiedCompaniesAddresses(req, res, next); + })(); + }, + Middleware.genericLoggingMiddleware, +); + +/* +app.post( + '/admin/verified-companies-addresses/add', + cors(corsOptions), + Middleware.authoriseAdminMiddleware, + (req: GeneralAdminRequest, res, next) => { + (async () => { + await AdminFunctions.GetVerifiedCompaniesAddresses(req, res, next); + })(); + }, + Middleware.genericLoggingMiddleware, +); + +app.delete( + '/admin/verified-companies-addresses/delete', + cors(corsOptions), + Middleware.authoriseAdminMiddleware, + (req: GeneralAdminRequest, res, next) => { + (async () => { + await AdminFunctions.GetVerifiedCompaniesAddresses(req, res, next); + })(); + }, + Middleware.genericLoggingMiddleware, +); +*/ if (env.NODE_ENV === 'development') { app.post('/email', (req, res) => { (async () => { diff --git a/backend/tests/admin_tests.js b/backend/tests/admin_tests.js index f0ee543ca..7c632636f 100644 --- a/backend/tests/admin_tests.js +++ b/backend/tests/admin_tests.js @@ -1576,6 +1576,50 @@ describe("admin", () => { } ); }); + + describe("test getting verified companies addresses", () => { + before( async function() { + // login as a student + this.studentToken = await server + .post("/authenticate/student") + .send({ zID: "literally", password: "anything" }) + .then(response => response.body.token); + + // login as an admin + this.adminToken = await server + .post("/authenticate/admin") + .send({ username: "admin", password: "incorrect pony plug paperclip" }) + .then(response => response.body.token); + }); + + it("fails to get companies addresses using student token", + function (done) { + server + .get("/admin/verified-companies-addresses") + .set("Authorization", this.studentToken) + .expect(401) + .end( function(_, res) { + expect(res.status).to.equal(401); + done(); + }); + } + ); + + it("successfully gets companies addresses using admin token", + function (done) { + server + .get("/admin/verified-companies-addresses") + .set("Authorization", this.adminToken) + .expect(200) + .end( function(_, res) { + expect(res.status).to.equal(200); + // TODO: add company addresses + expect(res.body.verifiedCompaniesAddresses).to.deep.equal([]); + done(); + }); + } + ); + }); }); From 951757d35c9562ae831cde2ef2c5be3532cf3fd0 Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Thu, 5 Oct 2023 12:46:28 +1100 Subject: [PATCH 3/5] implement addVerifiedAddresses endpoint --- backend/src/admin.ts | 69 ++++++++++++++++++-- backend/src/index.ts | 11 +++- backend/src/types/request.ts | 4 ++ backend/src/types/shared.ts | 4 ++ backend/tests/admin_tests.js | 123 ++++++++++++++++++++++++++--------- 5 files changed, 170 insertions(+), 41 deletions(-) diff --git a/backend/src/admin.ts b/backend/src/admin.ts index 9e9f9641c..3b457cad3 100644 --- a/backend/src/admin.ts +++ b/backend/src/admin.ts @@ -16,6 +16,7 @@ import { UnverifyCompanyAccountRequest, AdminCreateJobRequest, AdminApprovedJobPostsRequest, + AdminVerifiedCompaniesAddressesRequest, } from './types/request'; import { env } from './environment'; import AdminAccount from './entity/admin_account'; @@ -779,12 +780,11 @@ You job post request titled "${jobToReject.role}" has been rejected as it does n Logger.Info(LM, `ADMIN=${adminID} attempting to get verified companies email addresses`); - // Trying to select verifiedCompaniesAddresses returns an object rather than the array... - const adminAccount = await Helpers.doSuccessfullyOrFail( + const verifiedAddresses = await Helpers.doSuccessfullyOrFail( async () => AppDataSource.getRepository(AdminAccount) .createQueryBuilder() - // .select('AdminAccount.verifiedCompaniesAddresses') - .where('AdminAccount.id = :id', { id: adminID }) + .select(['AdminAccount.verifiedCompaniesAddresses']) + .where('id = :id', { id: adminID }) .getOne(), 'Failed to retrieve verified companies email addresses', ); @@ -793,12 +793,69 @@ You job post request titled "${jobToReject.role}" has been rejected as it does n return { status: StatusCodes.OK, - msg: { verifiedCompaniesAddresses: adminAccount.verifiedCompaniesAddresses }, + msg: { + verifiedCompaniesAddresses: verifiedAddresses.verifiedCompaniesAddresses, + token: req.newJbToken, + }, + }; + }, + () => ({ + status: StatusCodes.BAD_REQUEST, + msg: { token: req.newJbToken }, + }), + next, + ); + } + + public static async AddVerifiedCompaniesAddresses( + this: void, + req: AdminVerifiedCompaniesAddressesRequest, + res: Response, + next: NextFunction, + ) { + await Helpers.catchAndLogError( + res, + async (): Promise => { + const { adminID } = req; + Helpers.requireParameters(adminID); + Logger.Info(LM, `ADMIN=${adminID} attempting to add verified companies email addresses`); + + const adminAccount = await Helpers.doSuccessfullyOrFail( + async () => AppDataSource.getRepository(AdminAccount) + .createQueryBuilder() + .where('id = :id', { id: adminID }) + .getOne(), + `Failed to request admin account ID=${adminID}`, + ); + + const addressesToAdd = req.body.verifiedCompaniesAddresses; + Helpers.requireParameters(addressesToAdd); + + // Combine new addresses with existing ones, ensuring no duplicates + const allVerifiedAddresses = Array.from( + new Set(adminAccount.verifiedCompaniesAddresses.concat(addressesToAdd)), + ); + + // Update verifiedCompaniesAddresses column + await Helpers.doSuccessfullyOrFail( + async () => AppDataSource.createQueryBuilder() + .update(AdminAccount) + .set({ verifiedCompaniesAddresses: allVerifiedAddresses }) + .where('id = :id', { id: adminID }) + .execute(), + `Failed to save new addresses to admin account ID=${adminID}`, + ); + + Logger.Info(LM, `ADMIN=${adminID} successfully added verified companies email addresses`); + + return { + status: StatusCodes.OK, + msg: { token: req.newJbToken }, }; }, () => ({ status: StatusCodes.BAD_REQUEST, - msg: undefined, + msg: { token: req.newJbToken }, }), next, ); diff --git a/backend/src/index.ts b/backend/src/index.ts index 32bb24ab2..a82d940d6 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -41,6 +41,7 @@ import { StudentGetJobRequest, StudentPaginatedJobsRequest, UpdateCompanyDetailsRequest, + AdminVerifiedCompaniesAddressesRequest, VerifyCompanyAccountRequest, UnverifyCompanyAccountRequest, SearchJobRequest, @@ -530,19 +531,22 @@ app.get( Middleware.genericLoggingMiddleware, ); -/* +// TODO: create new type for GeneralAdminRequest - should take a list +// Implement AddVerifiedCompaniesAddresses +// Write tests app.post( '/admin/verified-companies-addresses/add', cors(corsOptions), Middleware.authoriseAdminMiddleware, - (req: GeneralAdminRequest, res, next) => { + (req: AdminVerifiedCompaniesAddressesRequest, res, next) => { (async () => { - await AdminFunctions.GetVerifiedCompaniesAddresses(req, res, next); + await AdminFunctions.AddVerifiedCompaniesAddresses(req, res, next); })(); }, Middleware.genericLoggingMiddleware, ); +/* app.delete( '/admin/verified-companies-addresses/delete', cors(corsOptions), @@ -555,6 +559,7 @@ app.delete( Middleware.genericLoggingMiddleware, ); */ + if (env.NODE_ENV === 'development') { app.post('/email', (req, res) => { (async () => { diff --git a/backend/src/types/request.ts b/backend/src/types/request.ts index bfc0ae3b3..66c2cce2a 100644 --- a/backend/src/types/request.ts +++ b/backend/src/types/request.ts @@ -15,6 +15,7 @@ import { Offset, StudentZID, StudentProfileInfo, + VerifiedCompaniesAddresses, Year, } from './shared'; @@ -53,6 +54,9 @@ export interface AdminCreateJobRequest export interface AdminApprovedJobPostsRequest extends Request, AdminRequestBase {} +export interface AdminVerifiedCompaniesAddressesRequest + extends Request, AdminRequestBase {} + // * Student export interface StudentPaginatedJobsRequest extends Request, diff --git a/backend/src/types/shared.ts b/backend/src/types/shared.ts index 8c8e36065..5f23c4500 100644 --- a/backend/src/types/shared.ts +++ b/backend/src/types/shared.ts @@ -84,3 +84,7 @@ export interface AuthBody { export interface Year { year: string; } + +export interface VerifiedCompaniesAddresses { + verifiedCompaniesAddresses: string[]; +} diff --git a/backend/tests/admin_tests.js b/backend/tests/admin_tests.js index 7c632636f..107f8b1b6 100644 --- a/backend/tests/admin_tests.js +++ b/backend/tests/admin_tests.js @@ -1577,48 +1577,107 @@ describe("admin", () => { ); }); - describe("test getting verified companies addresses", () => { - before( async function() { - // login as a student - this.studentToken = await server - .post("/authenticate/student") - .send({ zID: "literally", password: "anything" }) - .then(response => response.body.token); - - // login as an admin - this.adminToken = await server - .post("/authenticate/admin") - .send({ username: "admin", password: "incorrect pony plug paperclip" }) - .then(response => response.body.token); + describe("testing verified companies email addresses", () => { + describe("test adding verified companies addresses", () => { + before( async function() { + // login as a student + this.studentToken = await server + .post("/authenticate/student") + .send({ zID: "literally", password: "anything" }) + .then(response => response.body.token); + + // login as an admin + this.adminToken = await server + .post("/authenticate/admin") + .send({ username: "admin", password: "incorrect pony plug paperclip" }) + .then(response => response.body.token); + }); + + it("fails to add companies addresses using student token", + function (done) { + server + .post("/admin/verified-companies-addresses/add") + .set("Authorization", this.studentToken) + .send({ + verifiedCompaniesAddresses: ["example@example.com", "example2@example.com", "hi@hi.com"], + }) + .expect(401) + .end( function(_, res) { + expect(res.status).to.equal(401); + done(); + }); + } + ); + + it("successfully adds companies addresses using admin token", + function (done) { + server + .post("/admin/verified-companies-addresses/add") + .set("Authorization", this.adminToken) + .send({ + verifiedCompaniesAddresses: ["example@example.com", "example2@example.com", "hi@hi.com"], + }) + .expect(200) + .end( function(_, res) { + expect(res.status).to.equal(200); + done(); + }); + } + ); }); - - it("fails to get companies addresses using student token", + + describe("test getting verified companies addresses", () => { + before( async function() { + // login as a student + this.studentToken = await server + .post("/authenticate/student") + .send({ zID: "literally", password: "anything" }) + .then(response => response.body.token); + + // login as an admin + this.adminToken = await server + .post("/authenticate/admin") + .send({ username: "admin", password: "incorrect pony plug paperclip" }) + .then(response => response.body.token); + + // add some verified addresses + await server + .post("/admin/verified-companies-addresses/add") + .set("Authorization", this.adminToken) + .send({ + verifiedCompaniesAddresses: ["example@example.com", "example2@example.com", "hi@hi.com"], + }); + }); + + it("fails to get companies addresses using student token", + function (done) { + server + .get("/admin/verified-companies-addresses") + .set("Authorization", this.studentToken) + .expect(401) + .end( function(_, res) { + expect(res.status).to.equal(401); + done(); + }); + } + ); + + it("successfully gets companies addresses using admin token", function (done) { server .get("/admin/verified-companies-addresses") - .set("Authorization", this.studentToken) - .expect(401) + .set("Authorization", this.adminToken) + .expect(200) .end( function(_, res) { - expect(res.status).to.equal(401); + expect(res.status).to.equal(200); + expect(res.body.verifiedCompaniesAddresses).to.deep.members(["example@example.com", "example2@example.com", "hi@hi.com"]); done(); }); } ); + }); + - it("successfully gets companies addresses using admin token", - function (done) { - server - .get("/admin/verified-companies-addresses") - .set("Authorization", this.adminToken) - .expect(200) - .end( function(_, res) { - expect(res.status).to.equal(200); - // TODO: add company addresses - expect(res.body.verifiedCompaniesAddresses).to.deep.equal([]); - done(); - }); - } - ); }); }); From 333cc9ea81ad3d634c8afc2bd5823551fd5d09db Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Sun, 8 Oct 2023 22:52:40 +1100 Subject: [PATCH 4/5] implement deleting companies addresses --- backend/src/admin.ts | 56 ++++++++++-- backend/src/index.ts | 11 +-- backend/tests/admin_tests.js | 163 ++++++++++++++++++++++++++++++----- 3 files changed, 192 insertions(+), 38 deletions(-) diff --git a/backend/src/admin.ts b/backend/src/admin.ts index 3b457cad3..4d2047cbc 100644 --- a/backend/src/admin.ts +++ b/backend/src/admin.ts @@ -837,16 +837,58 @@ You job post request titled "${jobToReject.role}" has been rejected as it does n ); // Update verifiedCompaniesAddresses column - await Helpers.doSuccessfullyOrFail( - async () => AppDataSource.createQueryBuilder() - .update(AdminAccount) - .set({ verifiedCompaniesAddresses: allVerifiedAddresses }) + adminAccount.verifiedCompaniesAddresses = allVerifiedAddresses; + await AppDataSource.manager.save(adminAccount); + + Logger.Info(LM, `ADMIN=${adminID} successfully added verified companies email addresses`); + + return { + status: StatusCodes.OK, + msg: { token: req.newJbToken }, + }; + }, + () => ({ + status: StatusCodes.BAD_REQUEST, + msg: { token: req.newJbToken }, + }), + next, + ); + } + + public static async DeleteVerifiedCompaniesAddresses( + this: void, + req: AdminVerifiedCompaniesAddressesRequest, + res: Response, + next: NextFunction, + ) { + await Helpers.catchAndLogError( + res, + async (): Promise => { + const { adminID } = req; + Helpers.requireParameters(adminID); + Logger.Info(LM, `ADMIN=${adminID} attempting to delete verified companies email addresses`); + + const adminAccount = await Helpers.doSuccessfullyOrFail( + async () => AppDataSource.getRepository(AdminAccount) + .createQueryBuilder() .where('id = :id', { id: adminID }) - .execute(), - `Failed to save new addresses to admin account ID=${adminID}`, + .getOne(), + `Failed to request admin account ID=${adminID}`, ); - Logger.Info(LM, `ADMIN=${adminID} successfully added verified companies email addresses`); + const addressesToDelete = req.body.verifiedCompaniesAddresses; + Helpers.requireParameters(addressesToDelete); + + // Remove any addresses that appear in addressesToDelete + const allVerifiedAddresses = adminAccount.verifiedCompaniesAddresses.filter( + (address) => !addressesToDelete.includes(address), + ); + + // Update verifiedCompaniesAddresses column + adminAccount.verifiedCompaniesAddresses = allVerifiedAddresses; + await AppDataSource.manager.save(adminAccount); + + Logger.Info(LM, `ADMIN=${adminID} successfully deleted verified companies email addresses`); return { status: StatusCodes.OK, diff --git a/backend/src/index.ts b/backend/src/index.ts index a82d940d6..84d2fa04f 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -531,9 +531,6 @@ app.get( Middleware.genericLoggingMiddleware, ); -// TODO: create new type for GeneralAdminRequest - should take a list -// Implement AddVerifiedCompaniesAddresses -// Write tests app.post( '/admin/verified-companies-addresses/add', cors(corsOptions), @@ -546,19 +543,17 @@ app.post( Middleware.genericLoggingMiddleware, ); -/* -app.delete( +app.post( '/admin/verified-companies-addresses/delete', cors(corsOptions), Middleware.authoriseAdminMiddleware, - (req: GeneralAdminRequest, res, next) => { + (req: AdminVerifiedCompaniesAddressesRequest, res, next) => { (async () => { - await AdminFunctions.GetVerifiedCompaniesAddresses(req, res, next); + await AdminFunctions.DeleteVerifiedCompaniesAddresses(req, res, next); })(); }, Middleware.genericLoggingMiddleware, ); -*/ if (env.NODE_ENV === 'development') { app.post('/email', (req, res) => { diff --git a/backend/tests/admin_tests.js b/backend/tests/admin_tests.js index 107f8b1b6..6c5b2b27b 100644 --- a/backend/tests/admin_tests.js +++ b/backend/tests/admin_tests.js @@ -1578,6 +1578,49 @@ describe("admin", () => { }); describe("testing verified companies email addresses", () => { + describe("test getting verified companies addresses", () => { + before( async function() { + // login as a student + this.studentToken = await server + .post("/authenticate/student") + .send({ zID: "literally", password: "anything" }) + .then(response => response.body.token); + + // login as an admin + this.adminToken = await server + .post("/authenticate/admin") + .send({ username: "admin", password: "incorrect pony plug paperclip" }) + .then(response => response.body.token); + }); + + it("fails to get companies addresses using student token", + function (done) { + server + .get("/admin/verified-companies-addresses") + .set("Authorization", this.studentToken) + .expect(401) + .end( function(_, res) { + expect(res.status).to.equal(401); + done(); + }); + } + ); + + it("successfully gets companies addresses using admin token", + function (done) { + server + .get("/admin/verified-companies-addresses") + .set("Authorization", this.adminToken) + .expect(200) + .end( function(_, res) { + expect(res.status).to.equal(200); + expect(res.body.verifiedCompaniesAddresses.length).to.equal(0); + done(); + }); + } + ); + }); + describe("test adding verified companies addresses", () => { before( async function() { // login as a student @@ -1608,25 +1651,67 @@ describe("admin", () => { }); } ); - + it("successfully adds companies addresses using admin token", function (done) { + const adminToken = this.adminToken; + + // POST request to add addresses server .post("/admin/verified-companies-addresses/add") - .set("Authorization", this.adminToken) + .set("Authorization", adminToken) .send({ verifiedCompaniesAddresses: ["example@example.com", "example2@example.com", "hi@hi.com"], }) .expect(200) - .end( function(_, res) { - expect(res.status).to.equal(200); - done(); + .end( function(_, addRes) { + expect(addRes.status).to.equal(200); + + // GET request to check the addresses have been added + server + .get("/admin/verified-companies-addresses") + .set("Authorization", adminToken) + .expect(200) + .end( function(_, getRes) { + expect(getRes.status).to.equal(200); + expect(getRes.body.verifiedCompaniesAddresses).to.deep.members(["example@example.com", "example2@example.com", "hi@hi.com"]); + done(); + }); + }); + } + ); + + it("attempt to add duplicate addresses", + function (done) { + const adminToken = this.adminToken; + + // POST request to add addresses + server + .post("/admin/verified-companies-addresses/add") + .set("Authorization", adminToken) + .send({ + verifiedCompaniesAddresses: ["example@example.com", "example2@example.com", "hi@hi.com", "hi@hi.com"], + }) + .expect(200) + .end( function(_, addRes) { + expect(addRes.status).to.equal(200); + + // GET request to check the addresses have been added + server + .get("/admin/verified-companies-addresses") + .set("Authorization", adminToken) + .expect(200) + .end( function(_, getRes) { + expect(getRes.status).to.equal(200); + expect(getRes.body.verifiedCompaniesAddresses).to.deep.members(["example@example.com", "example2@example.com", "hi@hi.com"]); + done(); + }); }); } ); }); - - describe("test getting verified companies addresses", () => { + + describe("test deleting verified companies addresses", () => { before( async function() { // login as a student this.studentToken = await server @@ -1649,11 +1734,14 @@ describe("admin", () => { }); }); - it("fails to get companies addresses using student token", + it("fails to delete companies addresses using student token", function (done) { server - .get("/admin/verified-companies-addresses") + .post("/admin/verified-companies-addresses/delete") .set("Authorization", this.studentToken) + .send({ + verifiedCompaniesAddresses: ["example@example.com", "example2@example.com", "hi@hi.com"], + }) .expect(401) .end( function(_, res) { expect(res.status).to.equal(401); @@ -1662,22 +1750,51 @@ describe("admin", () => { } ); - it("successfully gets companies addresses using admin token", - function (done) { - server - .get("/admin/verified-companies-addresses") - .set("Authorization", this.adminToken) - .expect(200) - .end( function(_, res) { - expect(res.status).to.equal(200); - expect(res.body.verifiedCompaniesAddresses).to.deep.members(["example@example.com", "example2@example.com", "hi@hi.com"]); - done(); - }); - } - ); - }); + it("successfully deletes companies addresses using admin token", + function (done) { + const adminToken = this.adminToken; + // POST request to delete addresses + server + .post("/admin/verified-companies-addresses/delete") + .set("Authorization", adminToken) + .send({ + verifiedCompaniesAddresses: ["example@example.com", "hi@hi.com"], + }) + .expect(200) + .end( function(_, deleteRes) { + expect(deleteRes.status).to.equal(200); + + // GET request to check the addresses have been deleted + server + .get("/admin/verified-companies-addresses") + .set("Authorization", adminToken) + .expect(200) + .end( function(_, getRes) { + expect(getRes.status).to.equal(200); + expect(getRes.body.verifiedCompaniesAddresses).to.deep.members(["example2@example.com"]); + done(); + }); + }); + } + ); + it("attempt to delete non-existent addresses", + function (done) { + server + .post("/admin/verified-companies-addresses/delete") + .set("Authorization", this.adminToken) + .send({ + verifiedCompaniesAddresses: ["example3@example.com"], + }) + .expect(200) + .end( function(_, res) { + expect(res.status).to.equal(200); + done(); + }); + } + ); + }); }); }); From a0790145689092ca6ebaea898a335ca5da60a8d2 Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Mon, 9 Oct 2023 00:11:57 +1100 Subject: [PATCH 5/5] update backend documentation --- backend/src/admin.ts | 4 +- backend/src/docs/openapi.json | 100 ++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/backend/src/admin.ts b/backend/src/admin.ts index 4d2047cbc..b57f38230 100644 --- a/backend/src/admin.ts +++ b/backend/src/admin.ts @@ -838,7 +838,7 @@ You job post request titled "${jobToReject.role}" has been rejected as it does n // Update verifiedCompaniesAddresses column adminAccount.verifiedCompaniesAddresses = allVerifiedAddresses; - await AppDataSource.manager.save(adminAccount); + await AppDataSource.getRepository(AdminAccount).save(adminAccount); Logger.Info(LM, `ADMIN=${adminID} successfully added verified companies email addresses`); @@ -886,7 +886,7 @@ You job post request titled "${jobToReject.role}" has been rejected as it does n // Update verifiedCompaniesAddresses column adminAccount.verifiedCompaniesAddresses = allVerifiedAddresses; - await AppDataSource.manager.save(adminAccount); + await AppDataSource.getRepository(AdminAccount).save(adminAccount); Logger.Info(LM, `ADMIN=${adminID} successfully deleted verified companies email addresses`); diff --git a/backend/src/docs/openapi.json b/backend/src/docs/openapi.json index a67488978..97bfe2075 100644 --- a/backend/src/docs/openapi.json +++ b/backend/src/docs/openapi.json @@ -994,6 +994,70 @@ } } } + }, + "/admin/verified-companies-addresses": { + "get": { + "summary": "Returns a list of verified companies addresses", + "description": "Query the database to get a list of email addresses belonging to verified companies submitted by admin", + "tags": [ + "admin" + ], + "responses": { + "200": { + "description": "Successfully retrieved verified companies addresses", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/VerifiedCompaniesAddresses" + } + } + } + }, + "400": { + "description": "Failed to query the database and retrieve verified companies addresses" + } + } + } + }, + "/admin/verified-companies-addresses/add": { + "post": { + "summary": "Adds email addresses to list of known verified companies addresses", + "description": "Inserts specified email addresses into list of addresses belonging to verified companies in database", + "tags": [ + "admin" + ], + "requestBody": { + "$ref": "#/components/requestBodies/VerifiedCompaniesAddressesBody" + }, + "responses": { + "200": { + "description": "Successfully added verified companies addresses" + }, + "400": { + "description": "Failed to add verified companies addresses" + } + } + } + }, + "/admin/verified-companies-addresses/delete": { + "post": { + "summary": "Deletes email addresses from list of known verified companies addresses", + "description": "Deletes specified email addresses from list of addresses belonging to verified companies in database", + "tags": [ + "admin" + ], + "requestBody": { + "$ref": "#/components/requestBodies/VerifiedCompaniesAddressesBody" + }, + "responses": { + "200": { + "description": "Successfully added verified companies addresses" + }, + "400": { + "description": "Failed to add verified companies addresses" + } + } + } } }, "components": { @@ -1241,6 +1305,28 @@ } } } + }, + "VerifiedCompaniesAddressesBody": { + "description": "JSON object containing list of email addresses of verified companies", + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "verifiedCompaniesAddresses": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "example": { + "verifiedCompaniesAddresses": ["example@email.com", "example2@email.com"] + } + } + } } }, "schemas": { @@ -1567,6 +1653,20 @@ "wam": "HD", "workingRights": "no_wr" } + }, + "VerifiedCompaniesAddresses": { + "type": "object", + "properties": { + "verifiedCompaniesAddresses": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "example": { + "verifiedCompaniesAddresses": ["example@email.com", "example2@email.com"] + } } } }