-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate update scripts and delete prisma1
- Loading branch information
Showing
35 changed files
with
107 additions
and
22,807 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
4 changes: 2 additions & 2 deletions
4
...ma1/scripts/accept-pending-invitations.ts → ...sma/scripts/accept-pending-invitations.ts
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
File renamed without changes.
File renamed without changes.
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,50 @@ | ||
import axios from "axios"; | ||
import { addContact } from "src/common/mails.helper"; | ||
import prisma from "src/prisma"; | ||
import { Updater, registerUpdater } from "./helper/helper"; | ||
|
||
type Contact = { Email: string; Name?: string }; | ||
|
||
@registerUpdater( | ||
"Set contacts in Mailjet", | ||
`Add every user to Mailjet, so that the newsletter are automatically sent to everyone`, | ||
false | ||
) | ||
export class SetContactsUpdater implements Updater { | ||
run() { | ||
console.info("Starting script to set contacts in mailjet..."); | ||
|
||
try { | ||
return prisma.user | ||
.findMany({ orderBy: { createdAt: "desc" } }) | ||
.then(async users => { | ||
const latestContacts = await axios.get<Contact[]>( | ||
"http://td-mail/contact" | ||
); | ||
|
||
const contactsToCreate = []; | ||
for (const user of users) { | ||
// As soon as one of the user is in the 10 latest contacts, stop picking users | ||
if ( | ||
latestContacts.data.find(e => e.Email === user.email) !== | ||
undefined | ||
) { | ||
break; | ||
} | ||
contactsToCreate.push(user); | ||
} | ||
|
||
return Promise.all( | ||
contactsToCreate.map(c => | ||
addContact({ email: c.email, name: c.name }).catch(err => | ||
console.error(`Error for email ${c.email}`, err) | ||
) | ||
) | ||
); | ||
}); | ||
} catch (err) { | ||
console.error("☠ Something went wrong during the update", err); | ||
throw new Error(); | ||
} | ||
} | ||
} |
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,29 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
/** | ||
* To seed the DB, run `ts-node prisma/seed.ts` | ||
* It looks for a `seed.dev.ts` file and execute it. | ||
* Content should look something like: | ||
* | ||
* ``` | ||
* import { PrismaClient } from "@prisma/client"; | ||
* const prisma = new PrismaClient(); | ||
* const main = async () => { ... } | ||
* | ||
* main() | ||
* .catch(e => console.error(e)) | ||
* .finally(() => prisma.disconnect()) | ||
* ``` | ||
*/ | ||
const seedPath = path.join(__dirname, "seed.dev.ts"); | ||
|
||
(() => { | ||
try { | ||
fs.accessSync(seedPath); | ||
} catch (err) { | ||
return; | ||
} | ||
|
||
import(seedPath); | ||
})(); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.