As I understand it appwrite doesn't support transactions. I'm attempting to make a document in three separate collections at the same time when a user registers. If one fails I want all to fail. This is my attempt at that. Is it wrong?
async ({
email,
password,
firstName,
lastName,
buildings,
units,
roles,
}) => {
const { account, databases } = createAdminClient()
const user = await account.create(ID.unique(), email, password)
const userDetails = await databases.createDocument(
import.meta.env.DATABASE_ID,
import.meta.env.USER_DETAILS_ID,
user.$id,
{
firstName: firstName,
lastName: lastName,
},
)
if (!userDetails) {
await account.deleteIdentity(user.$id)
}
const unitUsers = await Promise.all(
buildings.map((building, index) => {
databases.createDocument(
import.meta.env.DATABASE_ID,
import.meta.env.UNIT_USERS_ID,
ID.unique(),
{
unitId: building + units[index],
userId: user.$id,
role: roles[index],
},
)
}),
)
if (!unitUsers) {
await account.deleteIdentity(user.$id)
await databases.deleteDocument(
import.meta.env.DATABASE_ID,
import.meta.env.USER_DETAILS_ID,
userDetails.$id,
)
}
if (user && userDetails && unitUsers) return { registered: true }
},
}),
This looks fine but you might want to add some sort of error handling so when something goes wrong it's easy to find what happened, and you can give a useful message to the user.
OK I'm going to be testing it very soon!
Recommended threads
- Appwrite + Cloudflare domain
So i have a domain with cloudflare, however i'm only given a new NS to change the domain to. im not 100% sure how i would do this and dthe docs aren't really ta...
- How to model user data and relationships...
I wonder how to model something like this: A user can create any amount of events. Each event belongs to one user. What I have done so far: Created a new tabl...
- IP / CIDR For Appwrite Cloud Functions
[I saw this message](https://discord.com/channels/564160730845151244/1330335737954046067) that went unanswered. I have the same question: what IP addresses / CI...