Skip to content

Commit

Permalink
added brand queries
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvangg committed Feb 19, 2025
1 parent e46fed3 commit 88e834b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './services/email.js'
export * from './services/email.js'
export * from './services/brand.js'
27 changes: 20 additions & 7 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

Expand All @@ -18,19 +18,32 @@ model User {
}

model Emails {
id String @id @map("_id") @default(cuid())
id String @id @default(cuid()) @map("_id")
subject String
sender String?
body String
html String
image String
messageId String
tags String?
tags String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Brand Brands? @relation(fields: [brandId], references: [id])
brandId String?
}

// model Tag {
// id Int @id @default(autoincrement())
// name String @unique
// }
model Domains {
id String @id @default(cuid())
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}


// model Brands {
// id String @id @default(cuid()) @map("_id")
// name String
// emails Emails[]
// createdAt DateTime @default(now())
// updatedAt DateTime @updatedAt
// }
48 changes: 48 additions & 0 deletions services/brand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { db } from "../lib/prisma.js";

export async function getBrands() {
const brands = await db.domains.findMany();
return brands;
}

export async function getBrand(id: string) {
const brand = await db.domains.findUnique({
where: {
id,
},
});
return brand;
}

export async function getBrandByQuery(query: any) {
const brand = await db.domains.findUnique({
where: {
...query,
},
});
return brand;
}

export async function deleteBrand(id: string) {
const brand = await db.domains.delete({
where: {
id,
},
});
return brand;
}

export async function updateBrand(id: string, data: any) {
const brand = await db.domains.update({
where: {
id,
},
data,
});
return brand;
}

export async function createBrand(data: any) {
const brand = await db.domains.create({ data });
return brand;
}
11 changes: 10 additions & 1 deletion services/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ async function getEmail(id: string) {
return template;
}

async function getEmailByQuery(query: any) {
const template = await db.emails.findMany({
where: {
...query,
},
});
return template;
}

async function deleteEmail(id: string) {
const template = await db.emails.delete({
where: {
Expand Down Expand Up @@ -50,4 +59,4 @@ async function createBatchEmails(data: any) {
return template;
}

export { getEmails, getEmail, deleteEmail, updateEmail, createEmail, createBatchEmails };
export { getEmails, getEmail, deleteEmail, updateEmail, createEmail, createBatchEmails, getEmailByQuery };

0 comments on commit 88e834b

Please sign in to comment.