all repos — caroster @ a91b6c5d105a9cd70ff19ccadb8f9e2b1b00016d

[Octree] Group carpool to your event https://caroster.io

backend/config/cron-tasks.ts (view raw)

 1import { DateTime } from "luxon";
 2import pMap from "p-map";
 3
 4export default {
 5  /**
 6   * Send event recap to creators
 7   * Everyday at 08:00
 8   */
 9  "0 8 * * *": async ({ strapi }) => {
10    const events = await strapi.entityService.findMany("api::event.event", {
11      filters: {
12        date: {
13          $gte: DateTime.now().toISODate(),
14        },
15      },
16      limit: -1,
17    });
18
19    await pMap(events, strapi.service("api::event.event").sendDailyRecap, {
20      concurrency: 5,
21    });
22  },
23  /**
24   * Send event recap when it has ended
25   * Only to events with a provided 'date' field
26   * Everyday at 08:30
27   */
28  "30 8 * * *": async ({ strapi }) => {
29    const events = await strapi.entityService.findMany("api::event.event", {
30      filters: {
31        date: {
32          $eq: DateTime.now().minus({ day: 1 }).toISODate(),
33        },
34      },
35      populate: ["travels", "passengers", "passengers.travel"],
36      limit: -1,
37    });
38    await pMap(events, strapi.service("api::event.event").sendEndRecap, {
39      concurrency: 5,
40    });
41  },
42  /**
43   * Clean unpaid events
44   * Every sunday at 02:00
45   */
46  "0 2 * * 0": async ({ strapi }) => {
47    try {
48      const { count } = await strapi.db.query("api::event.event").updateMany({
49        where: { unpaid: true },
50        data: { unpaid: false, enabled_modules: [] },
51      });
52      strapi.log.info(`${count} unpaid events reset to basic.`);
53    } catch (error) {
54      strapi.log.error(`Can't delete unpaid events`);
55      console.error(error);
56    }
57  },
58};