From 1bbfb7d12c42e3336ed248948e26f897f49dd83f Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Mon, 7 Dec 2020 12:10:07 +0100 Subject: [PATCH] fix updateProvider not possible to update provider so it can have both private person and organisation at the same time --- src/datasources/db/providerAPI.ts | 8 ++++++++ src/model/Provider.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/datasources/db/providerAPI.ts b/src/datasources/db/providerAPI.ts index dacece9..a72266c 100644 --- a/src/datasources/db/providerAPI.ts +++ b/src/datasources/db/providerAPI.ts @@ -145,6 +145,14 @@ export class ProviderAPI extends DataSource { } async updateProvider (provider: any, userId: number) { + // make sure that a provider cannot have both organisation and person at the same time + if (provider.privatePersonId && provider.organisationId) { return new UserInputError('Provider must have either privatePersonId or organisationId'); } + if (provider.privatePersonId) { + provider.organisationId = null; + } else if (provider.organisationId) { + provider.privatePersonId = null; + } + const keepLock = provider.keepLock; delete provider.keepLock; const cargoBikes = provider.cargoBikeIds; diff --git a/src/model/Provider.ts b/src/model/Provider.ts index c366be8..11e9b6e 100644 --- a/src/model/Provider.ts +++ b/src/model/Provider.ts @@ -52,7 +52,7 @@ export class Provider implements Lockable { id: number; @Column({ - nullable: false + nullable: true }) formName: String;