x
This commit is contained in:
1 parent
443bdfb6dc
commit
50b93eb629
20 files changed
+552
-435
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { Elysia, t } from "elysia";
|
||||
import prisma from "../lib/prisma.js";
|
||||
|
||||
export const contactsRoute = new Elysia({ prefix: "/contacts" })
|
||||
.post("/", async ({ body, set }) => {
|
||||
try {
|
||||
const { name, email, message } = body;
|
||||
|
||||
const contactMessage = await prisma.contactMessage.create({
|
||||
data: {
|
||||
name,
|
||||
email,
|
||||
message
|
||||
}
|
||||
});
|
||||
|
||||
return { success: true, data: contactMessage };
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
set.status = 500;
|
||||
return { success: false, error: "Failed to submit contact message" };
|
||||
}
|
||||
}, {
|
||||
body: t.Object({
|
||||
name: t.String({ minLength: 1 }),
|
||||
email: t.String({ format: "email" }),
|
||||
message: t.String({ minLength: 1 })
|
||||
})
|
||||
})
|
||||
.get("/", async () => {
|
||||
return await prisma.contactMessage.findMany({
|
||||
orderBy: { createdAt: "desc" }
|
||||
});
|
||||
})
|
||||
.patch("/:id", async ({ params, body, set }) => {
|
||||
try {
|
||||
const id = parseInt(params.id);
|
||||
const { isRead } = body;
|
||||
|
||||
const updated = await prisma.contactMessage.update({
|
||||
where: { id },
|
||||
data: { isRead }
|
||||
});
|
||||
|
||||
return { success: true, data: updated };
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
set.status = 500;
|
||||
return { success: false, error: "Failed to update contact message" };
|
||||
}
|
||||
}, {
|
||||
params: t.Object({
|
||||
id: t.String()
|
||||
}),
|
||||
body: t.Object({
|
||||
isRead: t.Boolean()
|
||||
})
|
||||
});
|
||||
Reference in new issue
Block a user