-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #3707 - Turbo87:invites, r=locks
mirage: Implement `crate_owner_invitations` endpoints This should simplify implementing #2868 in the future :)
- Loading branch information
Showing
8 changed files
with
256 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Factory } from 'ember-cli-mirage'; | ||
|
||
export default Factory.extend({ | ||
createdAt: '2016-12-24T12:34:56Z', | ||
token: i => `secret-token-${i}`, | ||
|
||
afterCreate(invite) { | ||
if (!invite.crateId) { | ||
throw new Error(`Missing \`crate\` relationship on \`crate-owner-invitation:${invite.id}\``); | ||
} | ||
if (!invite.inviteeId) { | ||
throw new Error(`Missing \`invitee\` relationship on \`crate-owner-invitation:${invite.id}\``); | ||
} | ||
if (!invite.inviterId) { | ||
throw new Error(`Missing \`inviter\` relationship on \`crate-owner-invitation:${invite.id}\``); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { belongsTo, Model } from 'ember-cli-mirage'; | ||
|
||
export default Model.extend({ | ||
crate: belongsTo(), | ||
invitee: belongsTo('user'), | ||
inviter: belongsTo('user'), | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import BaseSerializer from './application'; | ||
|
||
export default BaseSerializer.extend({ | ||
// eslint-disable-next-line ember/avoid-leaking-state-in-ember-objects | ||
include: ['inviter'], | ||
|
||
getHashForResource() { | ||
let [hash, addToIncludes] = BaseSerializer.prototype.getHashForResource.apply(this, arguments); | ||
|
||
if (Array.isArray(hash)) { | ||
for (let resource of hash) { | ||
this._adjust(resource); | ||
} | ||
} else { | ||
this._adjust(hash); | ||
} | ||
|
||
return [hash, addToIncludes]; | ||
}, | ||
|
||
_adjust(hash) { | ||
delete hash.id; | ||
delete hash.token; | ||
|
||
let crate = this.schema.crates.find(hash.crate_id); | ||
hash.crate_name = crate.name; | ||
|
||
hash.invitee_id = Number(hash.invitee_id); | ||
hash.inviter_id = Number(hash.inviter_id); | ||
|
||
let inviter = this.schema.users.find(hash.inviter_id); | ||
hash.invited_by_username = inviter.login; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.