Skip to content

Commit

Permalink
🔨 Update database seed script to new schema
Browse files Browse the repository at this point in the history
  • Loading branch information
leodr committed Feb 7, 2021
1 parent 7b01f9f commit e365851
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
1 change: 0 additions & 1 deletion api/submission/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class SubmissionService {
createdAt: firebase.firestore.FieldValue.serverTimestamp(),
data,
formId,
readAt: null,
done: false,
});
}
Expand Down
37 changes: 20 additions & 17 deletions scripts/seedDatabase.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require("dotenv").config({ path: ".env.local" });
const admin = require("firebase-admin");
const faker = require("faker");
require("dotenv").config({ path: ".env.local" });
const { prompt } = require("enquirer");
const { subMonths } = require("date-fns");
const { subMonths, isToday } = require("date-fns");

admin.initializeApp({
credential: admin.credential.cert({
Expand All @@ -15,32 +14,36 @@ admin.initializeApp({
const firestore = admin.firestore();

async function seed() {
const { testUserId } = await prompt({
type: "input",
name: "testUserId",
message: "Enter the ID of the test user",
});

const forms = [
{
name: "Sales Contact",
slug: "sales-contact",
description: "The sales contact form, found at acme.org/pricing.",
allowSubmissions: true,
color: "orange",
owner: { type: "user", id: testUserId },
},
{
name: "Feedback (On-Site)",
slug: "feedback-on-site",
description:
"The small text field for feedback found at the top of every of our pages.",
allowSubmissions: true,
color: "green",
owner: { type: "user", id: testUserId },
},
{
name: "General Contact",
slug: "general-contact",
description: "Our general contact form, found under acme.org/contact.",
allowSubmissions: true,
color: "indigo",
owner: { type: "user", id: testUserId },
},
{
name: "Personal Get in Touch",
slug: "personal-get-in-touch",
description:
"The personal contact form for Leo Driesch, found at acme.org/about.",
allowSubmissions: true,
color: "pink",
owner: { type: "user", id: testUserId },
},
];

Expand Down Expand Up @@ -78,7 +81,7 @@ async function seed() {
const submission = {
createdAt: admin.firestore.Timestamp.fromDate(submissionDate),
formId: salesForm.id,
readAt: null,
done: !isToday(submissionDate),
data: {
email: faker.internet.email(),
name: `${faker.name.firstName()} ${faker.name.lastName()}`,
Expand Down Expand Up @@ -122,7 +125,7 @@ async function seed() {
const submission = {
createdAt: admin.firestore.Timestamp.fromDate(submissionDate),
formId: feedbackForm.id,
readAt: null,
done: !isToday(submissionDate),
data: {
feedback: faker.lorem.sentences(),
},
Expand Down Expand Up @@ -152,7 +155,7 @@ async function seed() {
const submission = {
createdAt: admin.firestore.Timestamp.fromDate(submissionDate),
formId: contactForm.id,
readAt: null,
done: !isToday(submissionDate),
data: {
email: faker.internet.email(),
name: `${faker.name.firstName()} ${faker.name.lastName()}`,
Expand Down Expand Up @@ -196,7 +199,7 @@ async function seed() {
const submission = {
createdAt: admin.firestore.Timestamp.fromDate(submissionDate),
formId: personalForm.id,
readAt: null,
done: !isToday(submissionDate),
data: {
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
Expand Down
5 changes: 2 additions & 3 deletions src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ export interface Form extends FirebaseDoc {
name: string;
description: string;
slug: string;
allowSubmissions?: boolean;
allowSubmissions: boolean;
}

export interface FormSubmission extends FirebaseDoc {
createdAt: firebase.firestore.Timestamp;
data: JsonObject;
formId: string;
readAt?: firebase.firestore.Timestamp;
done?: boolean;
done: boolean;
}

0 comments on commit e365851

Please sign in to comment.