diff --git a/.bin/seed.sh b/.bin/seed.sh index 52d126c..9cfdf33 100755 --- a/.bin/seed.sh +++ b/.bin/seed.sh @@ -95,7 +95,7 @@ create_customer_api_key() { create_user() { id=$1 organisationId=$2 - status=$3 + emailAddress=$3 # create the dynnamodb item aws dynamodb put-item \ @@ -104,7 +104,7 @@ create_user() { --table-name "$USERS_TABLE_NAME" --item "{ \"UserId\": {\"S\": \"$id\"}, \"OrganisationId\": {\"S\": \"$organisationId\"}, - \"Status\": {\"S\": \"$status\"}, + \"EmailAddress\": {\"S\": \"$emailAddress\"}, \"CreatedAt\": {\"S\": \"$createdAt\"}, \"UpdatedAt\": {\"S\": \"$createdAt\"} }" @@ -119,9 +119,9 @@ create_customer_api_key "HUBPC7NFHXS6H3LKZCEW" "$usagePlanId" "VitXWo4eiEphvzqR: create_customer_api_key "HUBP4NMDNBUKZ168SQTL" "$usagePlanId" "CBsaehhd3Q/qDusw:yGfSGJgPtL8xMMpN9SFc+s+ZZXugnA1DOeu8A7HofaOR7qZMYN5pTZtjFs3HBM29ER4KA2tj9OnoKjUC" false create_table_without_range_key "$USERS_TABLE_NAME" "UserId" -create_user "1234" "local-development" "Unregistered" -create_user "2345" "local-development" "Unregistered" -create_user "3456" "local-development" "Unregistered" -create_user "4567" "local-development" "Unregistered" -create_user "4442615091686901" "A55244BE-486B-489F-B3DE-2B87EE471B82" "Authorised" -create_user "5580468525832191" "08961382-2C50-42B7-B8BE-7D143FCAA101" "Authorised" +create_user "1234" "local-development" "abcd@test.com" +create_user "2345" "local-development" "" +create_user "3456" "local-development" "test@test.com" +create_user "4567" "local-development" "" +create_user "4442615091686901" "A55244BE-486B-489F-B3DE-2B87EE471B82" "abc@test.com" +create_user "5580468525832191" "08961382-2C50-42B7-B8BE-7D143FCAA101" "xyz@test.com" diff --git a/.env.development b/.env.development index ab3cf8c..48b1d86 100644 --- a/.env.development +++ b/.env.development @@ -9,7 +9,7 @@ export ORGANISATIONS_TABLE_NAME=Organisations export PORT=5001 export REST_API_ID=amaanxvxk5 export REST_STAGE_NAME=development -export USAGE_PLAN_ID=vjk8cctv0e +export USAGE_PLAN_ID=xi6vv266pr export USAGE_PLAN_LIST_PAGINATION_LIMIT=100 export USAGE_PLAN_PER_FPO_BURST_LIMIT=100 export USAGE_PLAN_PER_FPO_RATE_LIMIT=100 diff --git a/spec/controllers/userControllerSpec.ts b/spec/controllers/userControllerSpec.ts index 1372283..3c24a27 100644 --- a/spec/controllers/userControllerSpec.ts +++ b/spec/controllers/userControllerSpec.ts @@ -18,6 +18,7 @@ describe('UserController', () => { let organisationRepository: jasmine.SpyObj let controller: UserController let getUserResult: Promise + let updateUserResult: Promise let getOrganisationResult: Promise let createOrganisationResult: Promise let updateOrganisationResult: Promise @@ -30,6 +31,7 @@ describe('UserController', () => { it('returns the user', async () => { user = new User() user.OrganisationId = 'organisationId' + user.EmailAddress = 'abc@test.com' organisation = new Organisation() getUserResult = Promise.resolve(user) getOrganisationResult = Promise.resolve(null) @@ -119,13 +121,61 @@ describe('UserController', () => { await controller.create(req, res) expect(userRepository.createUser).toHaveBeenCalledWith('id', 'organisationId') - expect(organisationRepository.getOrganisation).toHaveBeenCalledWith('organisationId') - expect(organisationRepository.createOrganisation).toHaveBeenCalledWith('organisationId') expect(res.statusCode).toBe(201) expect(res.data).toEqual({ ...user.toJson(), Status: organisation.Status }) }) }) + describe('updateUser', () => { + it('returns updated user', async () => { + user = new User() + user.UserId = 'userId' + user.OrganisationId = 'organisationId' + getUserResult = Promise.resolve(user) + updateUserResult = Promise.resolve(user) + getOrganisationResult = Promise.resolve(null) + createOrganisationResult = Promise.resolve(organisation) + updateOrganisationResult = Promise.resolve(organisation) + userRepository = jasmine.createSpyObj('UserRepository', { + createUser: Promise.resolve(user), + GetUser: getUserResult, + updateUser: updateUserResult + }) + + organisationRepository = jasmine.createSpyObj('OrganisationRepository', { + getOrganisation: getOrganisationResult, + createOrganisation: createOrganisationResult, + updateOrganisation: updateOrganisationResult + }) + userRepository.updateUser.bind(userRepository) + userRepository.createUser.bind(userRepository) + organisationRepository.getOrganisation.bind(organisationRepository) + organisationRepository.createOrganisation.bind(organisationRepository) + organisationRepository.updateOrganisation.bind(organisationRepository) + controller = new UserController(userRepository, organisationRepository) + req = { + params: { userId: 'userId' }, + body: { emailAddress: 'emailAddress' } + } as any + const res = { + status: function (code: number) { + this.statusCode = code + return this + }, + json: function (data: any) { + this.data = data + return this + } + } as any + + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + await controller.update(req, res) + expect(userRepository.updateUser).toHaveBeenCalledWith('userId', 'emailAddress') + expect(res.statusCode).toBe(200) + expect(res.data).toEqual({ userId: 'userId' }) + }) + }) + describe('updateOrganisation', () => { it('returns updated organisation', async () => { user = new User() @@ -150,7 +200,7 @@ describe('UserController', () => { controller = new UserController(userRepository, organisationRepository) req = { params: { organisationId: 'organisationId' }, - body: { applicationReference: 'reference', status: 'status' } + body: { applicationReference: 'reference', status: 'status', organisationName: 'organisationName', eoriNumber: 'eoriNumber', ukAcsReference: 'ukAcsReference' } } as any const res = { status: function (code: number) { @@ -165,8 +215,8 @@ describe('UserController', () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument await controller.updateOrganisation(req, res) - expect(organisationRepository.updateOrganisation).toHaveBeenCalledWith('organisationId', 'reference', 'status') - expect(res.statusCode).toBe(201) + expect(organisationRepository.updateOrganisation).toHaveBeenCalledWith('organisationId', 'reference', 'status', 'organisationName', 'eoriNumber', 'ukAcsReference') + expect(res.statusCode).toBe(200) expect(res.data).toEqual({ organisationId: 'organisationId' }) }) }) diff --git a/spec/models/organisationSpec.ts b/spec/models/organisationSpec.ts index be7b697..ee90aff 100644 --- a/spec/models/organisationSpec.ts +++ b/spec/models/organisationSpec.ts @@ -61,6 +61,9 @@ describe('Organisation', () => { it('returns a Organisation instance', () => { const item = { OrganisationId: 'the-id', + OrganisationName: 'the-organisation-name', + EoriNumber: 'the-eori-number', + UkAcsReference: 'the-uk-acs-reference', CreatedAt: new Date().toISOString(), UpdatedAt: new Date().toISOString(), Saved: false @@ -76,6 +79,9 @@ describe('Organisation', () => { it('returns a plain object', () => { const organisation = new Organisation() organisation.OrganisationId = 'the-id' + organisation.OrganisationName = 'the-organisation-name' + organisation.EoriNumber = 'the-eori-number' + organisation.UkAcsReference = 'the-uk-acs-reference' const actual = organisation.toItem() expect(actual).toEqual({ @@ -83,6 +89,9 @@ describe('Organisation', () => { Description: organisation.Description, Status: organisation.Status, ApplicationReference: organisation.ApplicationReference, + OrganisationName: organisation.OrganisationName, + EoriNumber: organisation.EoriNumber, + UkAcsReference: organisation.UkAcsReference, CreatedAt: organisation.CreatedAt, UpdatedAt: organisation.UpdatedAt }) @@ -101,6 +110,9 @@ describe('Organisation', () => { Description: organisation.Description, Status: organisation.Status, ApplicationReference: organisation.ApplicationReference, + OrganisationName: organisation.OrganisationName, + EoriNumber: organisation.EoriNumber, + UkAcsReference: organisation.UkAcsReference, CreatedAt: organisation.CreatedAt, UpdatedAt: organisation.UpdatedAt }) diff --git a/spec/models/userSpec.ts b/spec/models/userSpec.ts index 48a7c88..c618e72 100644 --- a/spec/models/userSpec.ts +++ b/spec/models/userSpec.ts @@ -63,6 +63,7 @@ describe('User', () => { const item = { UserId: 'the-id', OrganisationId: 'yodel', + EmailAddress: '', CreatedAt: new Date().toISOString(), UpdatedAt: new Date().toISOString(), Saved: false @@ -79,11 +80,13 @@ describe('User', () => { const user = new User() user.UserId = 'the-id' user.OrganisationId = 'the-fpo-id' + user.EmailAddress = 'abc@hmrc.gov.uk' const actual = user.toItem() expect(actual).toEqual({ UserId: 'the-id', OrganisationId: 'the-fpo-id', + EmailAddress: 'abc@hmrc.gov.uk', CreatedAt: user.CreatedAt, UpdatedAt: user.UpdatedAt }) @@ -100,6 +103,7 @@ describe('User', () => { expect(actual).toEqual({ UserId: 'the-id', OrganisationId: '', + EmailAddress: '', CreatedAt: user.CreatedAt, UpdatedAt: user.UpdatedAt }) diff --git a/spec/operations/getOrganisationSpec.ts b/spec/operations/getOrganisationSpec.ts index c4f8169..3d4e1c8 100644 --- a/spec/operations/getOrganisationSpec.ts +++ b/spec/operations/getOrganisationSpec.ts @@ -11,6 +11,10 @@ describe('GetOrganisation', () => { OrganisationId: { S: 'organisationId' }, Description: { S: 'description' }, Status: { S: 'Unregistered' }, + ApplicationReference: { S: 'ApplicationReference' }, + OrganisationName: { S: 'OrganisationName' }, + EoriNumber: { S: 'EoriNumber' }, + UkAcsReference: { S: 'UkAcsReference' }, CreatedAt: { S: new Date().toISOString() }, UpdatedAt: { S: new Date().toISOString() } }, diff --git a/spec/operations/getUserSpec.ts b/spec/operations/getUserSpec.ts index df3ca9d..f2904d7 100644 --- a/spec/operations/getUserSpec.ts +++ b/spec/operations/getUserSpec.ts @@ -11,6 +11,7 @@ describe('GetUser', () => { UserId: { S: 'userId' }, Status: { S: 'Unregistered' }, OrganisationId: { S: 'organisationId' }, + EmailAddress: { S: 'abc@test.com' }, CreatedAt: { S: new Date().toISOString() }, UpdatedAt: { S: new Date().toISOString() } }, diff --git a/spec/operations/updateOrganisationSpec.ts b/spec/operations/updateOrganisationSpec.ts index 4fc9bd1..a6e37f1 100644 --- a/spec/operations/updateOrganisationSpec.ts +++ b/spec/operations/updateOrganisationSpec.ts @@ -19,7 +19,7 @@ describe('CreateOrganisation', () => { }) it('updates existing organisation', async () => { - await updateOrganisation.call('organisationId', 'reference', 'status') + await updateOrganisation.call('organisationId', 'reference', 'status', 'organisationName', 'eoriNumber', 'uk') expect(dynamodbClient.send).toHaveBeenCalledTimes(1) }) }) diff --git a/spec/operations/updateUserSpec.ts b/spec/operations/updateUserSpec.ts new file mode 100644 index 0000000..5a2cadf --- /dev/null +++ b/spec/operations/updateUserSpec.ts @@ -0,0 +1,25 @@ +import 'jasmine' +import { type DynamoDBClient } from '@aws-sdk/client-dynamodb' +import { UpdateUser } from '../../src/operations/updateUser' + +describe('CreateUser', () => { + let dynamodbClient: jasmine.SpyObj + let updateUser: UpdateUser + + beforeEach(() => { + const dynamodbResult = { + $metadata: { + httpStatusCode: 201 + } + } + + dynamodbClient = jasmine.createSpyObj('DynamoDBClient', { send: Promise.resolve(dynamodbResult) }) + + updateUser = new UpdateUser(dynamodbClient) + }) + + it('updates existing User', async () => { + await updateUser.call('UserId', 'emailAddress') + expect(dynamodbClient.send).toHaveBeenCalledTimes(1) + }) +}) diff --git a/spec/repositories/organisationRepositorySpec.ts b/spec/repositories/organisationRepositorySpec.ts index 628c2f3..f55bcfb 100644 --- a/spec/repositories/organisationRepositorySpec.ts +++ b/spec/repositories/organisationRepositorySpec.ts @@ -69,9 +69,9 @@ describe('OrganisationRepository', () => { it('calls updateOperation', async () => { const organisation: Organisation = new Organisation() - await mockUpdateOperation.call(organisation.OrganisationId, organisation.ApplicationReference, organisation.Status) - await repository.updateOrganisation(organisation.OrganisationId, organisation.ApplicationReference, organisation.Status) - expect(mockUpdateOperation.call).toHaveBeenCalledWith(organisation.OrganisationId, organisation.ApplicationReference, organisation.Status) + await mockUpdateOperation.call(organisation.OrganisationId, organisation.ApplicationReference, organisation.Status, organisation.OrganisationName, organisation.EoriNumber, organisation.UkAcsReference) + await repository.updateOrganisation(organisation.OrganisationId, organisation.ApplicationReference, organisation.Status, organisation.OrganisationName, organisation.EoriNumber, organisation.UkAcsReference) + expect(mockUpdateOperation.call).toHaveBeenCalledWith(organisation.OrganisationId, organisation.ApplicationReference, organisation.Status, organisation.OrganisationName, organisation.EoriNumber, organisation.UkAcsReference) }) }) }) diff --git a/spec/repositories/userRepositorySpec.ts b/spec/repositories/userRepositorySpec.ts index 91e598f..6d3ad2d 100644 --- a/spec/repositories/userRepositorySpec.ts +++ b/spec/repositories/userRepositorySpec.ts @@ -5,6 +5,7 @@ import { UserRepository } from '../../src/repositories/userRepository' import { type CreateUser } from '../../src/operations/createUser' import { type GetUser } from '../../src/operations/getUser' +import { type UpdateUser } from '../../src/operations/updateUser' import { User } from '../../src/models/user' @@ -12,10 +13,12 @@ describe('UserRepository', () => { const dynamodbClient: DynamoDBClient = new DynamoDBClient({ region: 'us-west-2' }) const mockCreateOperation: jasmine.SpyObj = jasmine.createSpyObj('CreateUser', ['call']) const mockGetOperation: jasmine.SpyObj = jasmine.createSpyObj('GetUser', ['call']) + const mockUpdateOperation: jasmine.SpyObj = jasmine.createSpyObj('UpdateUser', ['call']) const repository: UserRepository = new UserRepository( dynamodbClient, mockCreateOperation, - mockGetOperation + mockGetOperation, + mockUpdateOperation ) describe('createUser', () => { @@ -44,6 +47,7 @@ describe('UserRepository', () => { result.UserId = 'id' result.OrganisationId = 'groupId' + result.EmailAddress = 'abc@hmrc.gov.uk' mockGetOperation.call.and.returnValue(Promise.resolve(result)) }) @@ -54,7 +58,27 @@ describe('UserRepository', () => { expect(actual).toEqual(jasmine.any(User)) expect(actual?.UserId).toEqual('id') expect(actual?.OrganisationId).toEqual('groupId') + expect(actual?.EmailAddress).toEqual('abc@hmrc.gov.uk') expect(mockGetOperation.call).toHaveBeenCalledWith('id') }) }) + + describe('updateUser', () => { + beforeEach(() => { + const result: User = new User() + + result.UserId = 'id' + result.EmailAddress = 'abc@hmrc.gov.uk' + + mockUpdateOperation.call.and.returnValue(Promise.resolve()) + }) + + it('calls updateUser', async () => { + const user: User = new User() + user.EmailAddress = 'abc@hmrc.gov.uk' + await mockUpdateOperation.call(user.UserId, user.EmailAddress) + await repository.updateUser(user.UserId, user.EmailAddress) + expect(mockUpdateOperation.call).toHaveBeenCalledWith(user.UserId, user.EmailAddress) + }) + }) }) diff --git a/src/controllers/usersController.ts b/src/controllers/usersController.ts index f0942c1..f0740e6 100644 --- a/src/controllers/usersController.ts +++ b/src/controllers/usersController.ts @@ -40,12 +40,33 @@ export class UserController { res.status(201).json({ ...user.toJson(), Status: status }) } + async update (req: Request, res: Response): Promise { + const userId = req.params.userId + const emailAddress = req.body.emailAddress as string + + await this.userRepository.updateUser(userId, emailAddress) + res.status(200).json({ userId }) + } + async updateOrganisation (req: Request, res: Response): Promise { const organisationId = req.params.organisationId const reference = req.body.applicationReference as string const status = req.body.status as string + const organisationName = req.body.organisationName as string + const eoriNumber = req.body.eoriNumber as string + const ukAcsReference = req.body.ukAcsReference as string + + await this.organisationRepository.updateOrganisation(organisationId, reference, status, organisationName, eoriNumber, ukAcsReference) + res.status(200).json({ organisationId }) + } - await this.organisationRepository.updateOrganisation(organisationId, reference, status) - res.status(201).json({ organisationId }) + async getOrganisation (req: Request, res: Response): Promise { + const organisationId = req.params.organisationId + const organisation = await this.organisationRepository.getOrganisation(organisationId) + if (organisation === null) { + res.status(404).json({ message: 'organisation not found' }) + } else { + res.status(200).json({ ...organisation.toJson() }) + } } } diff --git a/src/models/organisation.ts b/src/models/organisation.ts index e6c9b2d..22429b5 100644 --- a/src/models/organisation.ts +++ b/src/models/organisation.ts @@ -1,5 +1,6 @@ import { IsString, IsDateString } from 'class-validator' import { classToPlain, plainToClass } from 'class-transformer' +import getNestFieldValue from './utils' export class Organisation { @IsString() @@ -22,6 +23,15 @@ export class Organisation { @IsString() ApplicationReference: string + @IsString() + OrganisationName: string + + @IsString() + EoriNumber: string + + @IsString() + UkAcsReference: string + constructor () { this.OrganisationId = '' this.Description = '' @@ -29,6 +39,9 @@ export class Organisation { this.UpdatedAt = new Date().toISOString() this.Status = 'Unregistered' this.ApplicationReference = '' + this.OrganisationName = '' + this.EoriNumber = '' + this.UkAcsReference = '' this.Saved = false } @@ -39,13 +52,22 @@ export class Organisation { } static fromNestedItem (plainObject: any): Organisation { - const user = new Organisation() + const appReference = getNestFieldValue(plainObject, 'ApplicationReference') + const organisationName = getNestFieldValue(plainObject, 'organisationName') + const eoriNumber = getNestFieldValue(plainObject, 'EoriNumber') + const UkAcsReference = getNestFieldValue(plainObject, 'UkAcsReference') + const user = new Organisation() user.OrganisationId = plainObject.OrganisationId.S user.CreatedAt = plainObject.CreatedAt.S user.UpdatedAt = plainObject.UpdatedAt.S user.Status = plainObject.Status.S + user.ApplicationReference = appReference + user.OrganisationName = organisationName + user.EoriNumber = eoriNumber + user.UkAcsReference = UkAcsReference user.Saved = true + return user } diff --git a/src/models/user.ts b/src/models/user.ts index 8f5d996..eaf0ab0 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -1,5 +1,6 @@ import { IsString, IsDateString } from 'class-validator' import { classToPlain, plainToClass } from 'class-transformer' +import getNestFieldValue from './utils' export class User { @IsString() @@ -14,11 +15,15 @@ export class User { @IsDateString() UpdatedAt: string + @IsString() + EmailAddress: string + Saved: boolean constructor () { this.UserId = '' this.OrganisationId = '' + this.EmailAddress = '' this.CreatedAt = new Date().toISOString() this.UpdatedAt = new Date().toISOString() this.Saved = false @@ -32,9 +37,10 @@ export class User { static fromNestedItem (plainObject: any): User { const user = new User() - + const emailAddress = getNestFieldValue(plainObject, 'EmailAddress') user.UserId = plainObject.UserId.S user.OrganisationId = plainObject.OrganisationId.S + user.EmailAddress = emailAddress user.CreatedAt = plainObject.CreatedAt.S user.UpdatedAt = plainObject.UpdatedAt.S user.Saved = true diff --git a/src/models/utils.ts b/src/models/utils.ts new file mode 100644 index 0000000..5aee3ce --- /dev/null +++ b/src/models/utils.ts @@ -0,0 +1,7 @@ +export default function getNestFieldValue (plainObject: any, field: string): string { + let fieldValue = '' + if (Object.prototype.hasOwnProperty.call(plainObject, field)) { + fieldValue = plainObject[field].S + } + return fieldValue +} diff --git a/src/operations/updateOrganisation.ts b/src/operations/updateOrganisation.ts index 2cf7090..2cb9c39 100644 --- a/src/operations/updateOrganisation.ts +++ b/src/operations/updateOrganisation.ts @@ -9,16 +9,19 @@ class UpdateOrganisation { this.client = client } - async call (id: string, applicationReference: string, applicationStatus: string): Promise { + async call (id: string, applicationReference: string, applicationStatus: string, organisationName: string, eoriNumber: string, ukacsReference: string): Promise { const input: UpdateItemCommandInput = { TableName, Key: { OrganisationId: { S: id } }, - UpdateExpression: 'SET ApplicationReference = :applicationReference, #Status = :applicationStatus', + UpdateExpression: 'SET ApplicationReference = :applicationReference, #Status = :applicationStatus, OrganisationName = :organisationName, EoriNumber = :eoriNumber, UkAcsReference = :ukacsReference', ExpressionAttributeValues: { ':applicationReference': { S: applicationReference }, - ':applicationStatus': { S: applicationStatus } + ':applicationStatus': { S: applicationStatus }, + ':organisationName': { S: organisationName }, + ':eoriNumber': { S: eoriNumber }, + ':ukacsReference': { S: ukacsReference } }, ExpressionAttributeNames: { '#Status': 'Status' diff --git a/src/operations/updateUser.ts b/src/operations/updateUser.ts new file mode 100644 index 0000000..a503ea0 --- /dev/null +++ b/src/operations/updateUser.ts @@ -0,0 +1,31 @@ +import { UpdateItemCommand, type UpdateItemCommandInput, type DynamoDBClient } from '@aws-sdk/client-dynamodb' + +const TableName = process.env.USERS_TABLE_NAME ?? '' + +class UpdateUser { + private readonly client: DynamoDBClient + + constructor (client: DynamoDBClient) { + this.client = client + } + + async call (id: string, emailAddress: string): Promise { + const input: UpdateItemCommandInput = { + TableName, + Key: { + UserId: { S: id } + }, + UpdateExpression: 'SET EmailAddress = :emailAddress, UpdatedAt = :updatedAt', + ExpressionAttributeValues: { + ':emailAddress': { S: emailAddress }, + ':updatedAt': { S: new Date().toISOString() } + } + } + + const command = new UpdateItemCommand(input) + + await this.client.send(command) + } +} + +export { UpdateUser } diff --git a/src/repositories/organisationRepository.ts b/src/repositories/organisationRepository.ts index abbd1ad..23ebce9 100644 --- a/src/repositories/organisationRepository.ts +++ b/src/repositories/organisationRepository.ts @@ -21,7 +21,7 @@ export class OrganisationRepository { return await this.getOperation.call(id) } - async updateOrganisation (id: string, reference: string, status: string): Promise { - await this.updateOperation.call(id, reference, status) + async updateOrganisation (id: string, reference: string, status: string, organisationName: string, eoriNumber: string, ukacsReference: string): Promise { + await this.updateOperation.call(id, reference, status, organisationName, eoriNumber, ukacsReference) } } diff --git a/src/repositories/userRepository.ts b/src/repositories/userRepository.ts index b00ff59..4beb975 100644 --- a/src/repositories/userRepository.ts +++ b/src/repositories/userRepository.ts @@ -3,12 +3,14 @@ import { type User } from '../models/user' import { CreateUser } from '../operations/createUser' import { GetUser } from '../operations/getUser' +import { UpdateUser } from '../operations/updateUser' export class UserRepository { constructor ( private readonly dynamodbClient: DynamoDBClient, private readonly createOperation: CreateUser = new CreateUser(dynamodbClient), - private readonly getOperation: GetUser = new GetUser(dynamodbClient) + private readonly getOperation: GetUser = new GetUser(dynamodbClient), + private readonly updateOperation: UpdateUser = new UpdateUser(dynamodbClient) ) {} async createUser (id: string, organisationId: string): Promise { @@ -18,4 +20,8 @@ export class UserRepository { async getUser (id: string): Promise { return await this.getOperation.call(id) } + + async updateUser (id: string, emailAddress: string): Promise { + await this.updateOperation.call(id, emailAddress) + } } diff --git a/src/routes/api.ts b/src/routes/api.ts index a6fe825..471d1bf 100644 --- a/src/routes/api.ts +++ b/src/routes/api.ts @@ -47,8 +47,10 @@ router.delete('/keys/:organisationId/:id', (req, res) => { apiKeyController.dest router.post('/users/:id', (req, res) => { userController.create(req, res) }) router.get('/users/:id', (req, res) => { userController.show(req, res) }) +router.patch('/users/:id', (req, res) => { userController.update(req, res) }) router.patch('/organisations/:organisationId', (req, res) => { userController.updateOrganisation(req, res) }) +router.get('/organisations/:organisationId', (req, res) => { userController.getOrganisation(req, res) }) /* eslint-enable @typescript-eslint/no-floating-promises */