import moment from 'moment' import chunk from 'lodash/chunk' import { prismaClient as prisma } from '../../prismaClient' /** * Those 2 scripts were used because we had some problem with SendGrid * Events... so we decided to faked the deliveries and the seen */ // prisma.notification // .updateMany({ // where: { // sentByEmail: true, // createdAt: { // gte: moment().subtract(2, 'days').toDate(), // }, // }, // data: { // delivered: true, // deliveredByEmail: true, // }, // }) // .then(console.log) // prisma.notification // .findMany({ // where: { // hasBeenSeen: false, // deliveredByEmail: true, // createdAt: { // gte: moment().subtract(2, 'days').toDate(), // }, // }, // select: { // id: true, // hasBeenSeen: true, // user: { // select: { // hasInstalledApp: true, // }, // }, // }, // }) // .then(async (notifications) => { // console.log('notifications.length', notifications.length) // const chunks = chunk(notifications, 200) // console.log('chunks.length', chunks.length) // for await (const chunkOfNotifications of chunks) { // console.log('chunkOfNotifications.length', chunkOfNotifications.length) // const notifToUpdate = chunkOfNotifications.filter( // ({ user, hasBeenSeen }) => user && !user.hasInstalledApp && !hasBeenSeen // ) // console.log('processing notifications:', notifToUpdate.length) // await Promise.all( // notifToUpdate.map((notification) => // prisma.notification.update({ // where: { id: notification.id }, // data: { // hasBeenSeen: true, // hasBeenSeenByEmail: true, // }, // }) // ) // ) // } // console.log('done') // }) // .catch(console.error)