Skip to content

Instantly share code, notes, and snippets.

@coreysan
Created September 18, 2018 19:42
Show Gist options
  • Save coreysan/efcdb2502bc5e1a2808bdc613807ee66 to your computer and use it in GitHub Desktop.
Save coreysan/efcdb2502bc5e1a2808bdc613807ee66 to your computer and use it in GitHub Desktop.
const setAssignedUsers = async () => {
const randomTeamUsers = await TeamMember.forge()
.orderRand()
.fetchAll();
return Promise.all(
randomTeamUsers.map(async teamUser => {
const fellowTeamUser = await getFellowTeamUser(teamUser);
const userCustomer = await ContactUser.forge()
.where('user_id', teamUser.get('user_id'))
.orderRand()
.limit(1)
.fetch();
return Contact
.where('id', userCustomer.get('contact_id'))
.save({ idAssignedUser: fellowTeamUser.get('user_id') })
.catch(error => {
throw error;
});
// const contact = await Contact
// .where('id', userCustomer.get('contact_id'))
// .fetch();
// if (!contact) {
// throw new Error(`No contact found for id ${userCustomer.get('contact_id')}`);
// }
// return contact
// .update('idAssignedUser', fellowTeamUser.get('user_id'))
// .catch(error => {
// throw error;
// });
}),
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment