Created
September 18, 2018 19:42
-
-
Save coreysan/efcdb2502bc5e1a2808bdc613807ee66 to your computer and use it in GitHub Desktop.
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
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