-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: get reminders working again (#6)
* fix: get reminders working again * ci: generate prisma types before formatting
- Loading branch information
1 parent
84f38ad
commit d782f81
Showing
18 changed files
with
445 additions
and
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { errorBoundary } from '@stayradiated/error-boundary' | ||
import { prisma } from './prisma.js' | ||
|
||
type DeleteUserOptions = { | ||
userId: string | ||
} | ||
|
||
const deleteUser = async ( | ||
options: DeleteUserOptions, | ||
): Promise<void | Error> => { | ||
const { userId } = options | ||
return errorBoundary(async () => { | ||
const deletePostItems = prisma.postItem.deleteMany({ | ||
where: { post: { userId } }, | ||
}) | ||
const deletePosts = prisma.post.deleteMany({ where: { userId } }) | ||
const deleteReminder = prisma.reminder.deleteMany({ | ||
where: { userId }, | ||
}) | ||
const deleteUser = prisma.user.delete({ where: { id: userId } }) | ||
await prisma.$transaction([ | ||
deletePostItems, | ||
deletePosts, | ||
deleteReminder, | ||
deleteUser, | ||
]) | ||
}) | ||
} | ||
|
||
export { deleteUser } |
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
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,48 @@ | ||
import type { WebClient } from '@slack/web-api' | ||
import { formatDateAsISODate } from '../../date-utils.js' | ||
import { sendReminderToUser } from './send-reminder-to-user.js' | ||
import { findUsersWhoNeedReminder } from './find-users-who-need-reminder.js' | ||
|
||
type CheckAndRemindUsersOptions = { | ||
web: WebClient | ||
daysSinceLastPostCutOff: number | ||
defaultDailyReminderTime: string | ||
} | ||
const checkAndRemindUsers = async ( | ||
options: CheckAndRemindUsersOptions, | ||
): Promise<void | Error> => { | ||
const { web, daysSinceLastPostCutOff, defaultDailyReminderTime } = options | ||
|
||
const instant = Date.now() | ||
|
||
const userList = await findUsersWhoNeedReminder({ | ||
daysSinceLastPostCutOff, | ||
defaultDailyReminderTime, | ||
}) | ||
if (userList instanceof Error) { | ||
return userList | ||
} | ||
|
||
const result = await Promise.all( | ||
userList.map(async (user) => { | ||
const userDate = formatDateAsISODate({ | ||
instant, | ||
timeZone: user.timeZone, | ||
}) | ||
|
||
const sendReminderToUserResult = await sendReminderToUser({ | ||
web, | ||
user, | ||
userDate, | ||
daysSinceLastPostCutOff, | ||
}) | ||
|
||
return sendReminderToUserResult | ||
}), | ||
) | ||
if (result instanceof Error) { | ||
return result | ||
} | ||
} | ||
|
||
export { checkAndRemindUsers } |
Oops, something went wrong.