Skip to content

Commit

Permalink
Merge pull request #644 from desci-labs/contrib-fix
Browse files Browse the repository at this point in the history
Contributor fixes
  • Loading branch information
kadamidev authored Nov 20, 2024
2 parents 9a9d9da + 801257b commit 0fde4b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions desci-server/src/controllers/nodes/contributions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const addContributor = async (req: AddContributorRequest, res: Response<A
if (!userId && !email && !orcid) {
return res.status(400).json({ error: 'userId, Email or Orcid required' });
}
// debugger;
debugger; //
// Add contributor to the db
try {
const contributorAdded = await contributorService.addNodeContribution({
Expand All @@ -70,7 +70,7 @@ export const addContributor = async (req: AddContributorRequest, res: Response<A
});
if (!contributorAdded) throw Error('Failed to add contributor');

if (!email && contributorAdded.userId !== undefined) {
if (!email && !!contributorAdded.userId) {
// If the contributor being added has an existing account, their email is available on their profile.
const invitedContributor = await prisma.user.findUnique({ where: { id: contributorAdded.userId } });
if (invitedContributor?.email) email = invitedContributor.email;
Expand All @@ -90,7 +90,7 @@ export const addContributor = async (req: AddContributorRequest, res: Response<A
nodeUuid: node.uuid,
privShareCode: shareCode,
contributorId: contributorAdded.contributorId,
newUser: contributorAdded.userId === undefined,
newUser: !!!contributorAdded.userId,
});
const emailMsg = {
to: email,
Expand All @@ -101,7 +101,7 @@ export const addContributor = async (req: AddContributorRequest, res: Response<A
html: emailHtml,
};

if (contributorAdded.userId !== undefined) {
if (!!contributorAdded.userId) {
// Emit push notif to contributor if they already have a nodes account
await emitNotificationOnContributorInvite({
node: node,
Expand Down
6 changes: 3 additions & 3 deletions desci-server/src/controllers/nodes/contributions/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const updateContributor = async (req: UpdateContributorRequest, res: Resp
if (contributorUpdated) {
logger.info({ contributorUpdated }, 'Contributor updated successfully');

if (!email && contributorUpdated.userId !== undefined) {
if (!email && !!contributorUpdated.userId) {
// If the contributor being added has an existing account, their email is available on their profile.
const invitedContributor = await prisma.user.findUnique({ where: { id: contributorUpdated.userId } });
if (invitedContributor?.email) email = invitedContributor.email;
Expand All @@ -92,7 +92,7 @@ export const updateContributor = async (req: UpdateContributorRequest, res: Resp
nodeUuid: node.uuid,
privShareCode: shareCode,
contributorId: contributorUpdated.contributorId,
newUser: contributorUpdated.userId === undefined,
newUser: !!!contributorUpdated.userId,
});
const emailMsg = {
to: email,
Expand All @@ -103,7 +103,7 @@ export const updateContributor = async (req: UpdateContributorRequest, res: Resp
html: emailHtml,
};

if (contribution.userId === undefined && contributorUpdated.userId !== undefined) {
if (!!!contribution.userId && !!contributorUpdated.userId) {
// Emit push notif to contributor if the previous contribution entry didn't have a nodes account associated,
// but the updated entry now has a nodes account associated.
await emitNotificationOnContributorInvite({
Expand Down

0 comments on commit 0fde4b4

Please sign in to comment.