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;