Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/api/notification/services/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,18 @@ export default factories.createCoreService(MODULE_ID, ({ strapi }) => {
}
)
},
updateLastConsumedNotificationDate() {
async updateLastConsumedNotificationDate() {
const existing = await strapi.entityService.findOne(NOTIFICATIONS_CONSUMER_MODULE_ID, SINGLETON_ID)

if (!existing) {
return strapi.entityService.create(
NOTIFICATIONS_CONSUMER_MODULE_ID,
{
data: { lastConsumedNotificationDate: new Date() }
}
)
}

return strapi.entityService.update(
NOTIFICATIONS_CONSUMER_MODULE_ID,
SINGLETON_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ export default factories.createCoreController(MODULE_ID, ({strapi}) => {
throw new errors.ValidationError('Invalid telegram authentication data')
}

const existing = await strapi.entityService.findMany(MODULE_ID, { filters: { account, chatId: data.id } })
const existing = await strapi.entityService.findMany(MODULE_ID, {
filters: {
account: {
$eqi: account
}, chatId: data.id
}
})

/**
* We will only return true if the subscription belongs to the Telegram owner
Expand Down
10 changes: 5 additions & 5 deletions src/api/telegram-subscription/services/telegram-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default factories.createCoreService(MODULE_ID, ({strapi}) => {
MODULE_ID,
{
data: {
account,
account: account.toLowerCase(),
authDate: data.auth_date,
firstName: data.first_name,
hash: data.hash,
Expand All @@ -57,9 +57,7 @@ export default factories.createCoreService(MODULE_ID, ({strapi}) => {
MODULE_ID,
{
filters: {
account: {
$in: accounts
}
$or: accounts.map(account => ({ account: { $eqi: account } }))
},
fields: ['id', 'account', 'chatId']
}
Expand All @@ -70,7 +68,9 @@ export default factories.createCoreService(MODULE_ID, ({strapi}) => {
MODULE_ID,
{
filters: {
account
account: {
$eqi: account
}
},
fields: ['id', 'account', 'chatId']
}
Expand Down
Loading