Skip to content

Commit a4288b1

Browse files
committed
mirage: Allow adding multiple owners in the same API call
1 parent a53eff1 commit a4288b1

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

mirage/route-handlers/crates.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,20 @@ export function register(server) {
240240
}
241241

242242
const body = JSON.parse(request.requestBody);
243-
const [ownerId] = body.owners;
244-
const invitee = schema.users.findBy({ login: ownerId });
245243

246-
if (!invitee) {
247-
return { errors: [{ detail: `could not find user with login \`${ownerId}\`` }] };
244+
let users = [];
245+
for (let login of body.owners) {
246+
let user = schema.users.findBy({ login });
247+
if (!user) {
248+
return new Response(404, {}, { errors: [{ detail: `could not find user with login \`${login}\`` }] });
249+
}
250+
251+
users.push(user);
248252
}
249253

250-
schema.crateOwnerInvitations.create({ crate, inviter: user, invitee });
254+
for (let invitee of users) {
255+
schema.crateOwnerInvitations.create({ crate, inviter: user, invitee });
256+
}
251257

252258
return { ok: true };
253259
});

0 commit comments

Comments
 (0)