You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a multi-tenant application with some significant tenant isolation changes from the example/plugin. As part of this, I'm trying to implement an email uniqueness check with different validation rules. That is: if the user already exists in the DB and a tenant-admin attempts to add them to a new tenant, that operation should still "succeed" but be converted from a create to an update operation. Something like the following:
fields: [{name: 'email',type: 'email',required: true,access: {update: adminField,},hooks: {beforeValidate: [testEmailUniqueness]}}]...consttestEmailUniqueness: FieldHook<User>=async({
data, originalDoc, req, value, operation
})=>{
...
// if the user matches the current tenant, this is a true validation error// if the user exists but on another tenant, modify that user
... (iffirstcondition)thrownewValidationError({errors: [{message: `User with email ${value} exists for this tenant`,path: 'email',}]})}else{awaitpayload.update({collection: 'users',id: existingUser.id,data: {tenants: [...data.tenants, ...existingUser.tenants]},})returnfalse// unclear what return value should be}}
A few questions:
Is this type of operation possible?
What should the return value be from the hook?
Is it still possible to wrap this all in the same DB transaction?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm writing a multi-tenant application with some significant tenant isolation changes from the example/plugin. As part of this, I'm trying to implement an email uniqueness check with different validation rules. That is: if the user already exists in the DB and a tenant-admin attempts to add them to a new tenant, that operation should still "succeed" but be converted from a
create
to anupdate
operation. Something like the following:A few questions:
Beta Was this translation helpful? Give feedback.
All reactions