Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
chore: cleanup queue
Browse files Browse the repository at this point in the history
  • Loading branch information
2wce committed Mar 6, 2024
1 parent 893fde3 commit 9c1bfae
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 58 deletions.
16 changes: 6 additions & 10 deletions src/app/auth/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,12 @@ export default {
OTP: resetPasswordOtp,
});

try {
// Send an email to the user.
emailQueue.add({
recipientEmail: user.email,
html: message,
subject: "Forgot Password",
});
} catch (err) {
throw new Error("Failed to send email");
}
// Send an email to the user.
emailQueue.add({
recipientEmail: user.email,
html: message,
subject: "Forgot Password",
});

return true;
} catch (error) {
Expand Down
68 changes: 34 additions & 34 deletions src/utils/factory.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import prisma from "@/config/database";
import { faker } from "@faker-js/faker";
import { Prisma, PrismaClient } from "@prisma/client";
import { Prisma } from "@prisma/client";
import * as Factory from "factory.ts";

const { commerce, internet, person } = faker;
const prisma = new PrismaClient();

export interface TableList {
TABLE_NAME: string;
TABLE_NAME: string;
}

export const userFactory =
Factory.Sync.makeFactory<Prisma.UserUncheckedCreateInput>({
name: Factory.Sync.each(() => {
return person.firstName();
}),
surname: Factory.Sync.each(() => {
return person.lastName();
}),
email: Factory.Sync.each((seq) => {
return `seq_${seq}_${internet.email()}`;
}),
password: Factory.Sync.each(() => {
return internet.password();
}),
});
Factory.Sync.makeFactory<Prisma.UserUncheckedCreateInput>({
name: Factory.Sync.each(() => {
return person.firstName();
}),
surname: Factory.Sync.each(() => {
return person.lastName();
}),
email: Factory.Sync.each((seq) => {
return `seq_${seq}_${internet.email()}`;
}),
password: Factory.Sync.each(() => {
return internet.password();
}),
});

export const postFactory =
Factory.Sync.makeFactory<Prisma.PostUncheckedCreateInput>({
title: Factory.Sync.each(() => {
return commerce.productName();
}),
content: Factory.Sync.each(() => {
return commerce.productDescription();
}),
published: true,
});
Factory.Sync.makeFactory<Prisma.PostUncheckedCreateInput>({
title: Factory.Sync.each(() => {
return commerce.productName();
}),
content: Factory.Sync.each(() => {
return commerce.productDescription();
}),
published: true,
});

export const clearData = async () => {
try {
const posts = await prisma.post.deleteMany();
const users = await prisma.user.deleteMany();
try {
const posts = await prisma.post.deleteMany();
const users = await prisma.user.deleteMany();

console.log({ posts, users });
} catch (error) {
console.error(error);
return error;
}
console.log({ posts, users });
} catch (error) {
console.error(error);
return error;
}
};
28 changes: 14 additions & 14 deletions src/utils/generateSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const directoryPath = path.join(import.meta.dir, "../app");
// This is done recursively, so it includes files in subdirectories.
// The 'withFileTypes' option is set to 'true', so the returned array includes 'Dirent' objects instead of strings.
const files = await readdir(directoryPath, {
recursive: true,
withFileTypes: true,
recursive: true,
withFileTypes: true,
});

// Filter the files to get only the schema.
Expand All @@ -22,13 +22,13 @@ const schemaFiles = files.filter((file) => isSchema(file));
const schemas = [];

for (const schemaFile of schemaFiles) {
const { default: schemaExport } = await import(
`${directoryPath}/${schemaFile.name}`
);
const { default: schemaExport } = await import(
`${directoryPath}/${schemaFile.name}`
);

const schema = await Bun.file(schemaExport, { type: "graphql" }).text();
const schema = await Bun.file(schemaExport, { type: "graphql" }).text();

schemas.push(schema);
schemas.push(schema);
}

// Return the merged schema.
Expand All @@ -40,24 +40,24 @@ const mutationMatches = schema.match(/type Mutation \{([^}]*)\}/gs);

// Extract the fields from the Mutation types and trim them
const mutationFields = mutationMatches?.map((match) =>
match.replace(/type Mutation \{|\}/g, "").trim(),
match.replace(/type Mutation \{|\}/g, "").trim(),
);

// Match the contents of the Mutation types
// Match the contents of the Query types
const queryMatches = schema.match(/type Query \{([^}]*)\}/gs);

// Extract the fields from the Mutation types and trim them
// Extract the fields from the Query types and trim them
const queryFields = queryMatches?.map((match) =>
match.replace(/type Query \{|\}/g, "").trim(),
match.replace(/type Query \{|\}/g, "").trim(),
);

// Trim the fields to remove leading and trailing whitespace
const mutation = mutationFields?.join(spacing).trim();
const query = queryFields?.join(spacing).trim();
const rest = schema
.replace(/type Mutation \{([^}]*)\}/gs, "")
.replace(/type Query \{([^}]*)\}/gs, "")
.trim();
.replace(/type Mutation \{([^}]*)\}/gs, "")
.replace(/type Query \{([^}]*)\}/gs, "")
.trim();

// Combine the Mutation and Query types
const combinedSchema = `
Expand Down

0 comments on commit 9c1bfae

Please sign in to comment.