-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscribe task, proposal, deliverable creator to task
- Loading branch information
Showing
5 changed files
with
57 additions
and
3 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
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
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,45 @@ | ||
import { Sequelize, WhereOptions } from "sequelize"; | ||
|
||
import models from "src/db"; | ||
import logger from "src/utils/logger-handler"; | ||
|
||
export async function subscribeUserToTask(taskId: number, userAddress: string) { | ||
const where: WhereOptions = { | ||
address: Sequelize.where(Sequelize.fn("lower", Sequelize.col("address")), userAddress?.toLowerCase()), | ||
}; | ||
|
||
const user = await models.users.findOne({ where }); | ||
|
||
if (!user) { | ||
logger.warn(`Failed to subscribeUserToTask: user not found`, { taskId, userAddress }); | ||
return; | ||
} | ||
|
||
const task = await models.issues.findOne({ | ||
where: { | ||
id: taskId | ||
} | ||
}); | ||
|
||
if (!task) { | ||
logger.warn(`Failed to subscribeUserToTask: task not found`, { taskId, userAddress }); | ||
return; | ||
} | ||
|
||
const settings = await models.notification_settings.findOne({ | ||
where: { | ||
userId: user.id | ||
} | ||
}); | ||
|
||
|
||
if (!settings?.subscriptions) { | ||
logger.warn(`Failed to subscribeUserToTask: notification settings not found`, { taskId, userAddress }); | ||
return; | ||
} | ||
|
||
if (!settings.subscriptions.includes(taskId)) | ||
await settings.update({ | ||
subscriptions: [...settings.subscriptions, taskId] | ||
}); | ||
} |