mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
wip
This commit is contained in:

committed by
Geoff Seemueller

parent
21d6c8604e
commit
554096abb2
52
packages/services/src/contact-service/ContactService.ts
Normal file
52
packages/services/src/contact-service/ContactService.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
// ContactService.ts
|
||||
import { ContactRecord, Schema } from '@open-gsio/schema';
|
||||
import { types, flow, getSnapshot } from 'mobx-state-tree';
|
||||
|
||||
export default types
|
||||
.model('ContactStore', {})
|
||||
.volatile(self => ({
|
||||
env: {} as Env,
|
||||
ctx: {} as ExecutionContext,
|
||||
}))
|
||||
.actions(self => ({
|
||||
setEnv(env: Env) {
|
||||
self.env = env;
|
||||
},
|
||||
setCtx(ctx: ExecutionContext) {
|
||||
self.ctx = ctx;
|
||||
},
|
||||
handleContact: flow(function* (request: Request) {
|
||||
try {
|
||||
const { markdown: message, email, firstname, lastname } = yield request.json();
|
||||
const contactRecord = Schema.ContactRecord.create({
|
||||
message,
|
||||
timestamp: new Date().toISOString(),
|
||||
email,
|
||||
firstname,
|
||||
lastname,
|
||||
});
|
||||
const contactId = crypto.randomUUID();
|
||||
yield self.env.KV_STORAGE.put(
|
||||
`contact:${contactId}`,
|
||||
JSON.stringify(getSnapshot(contactRecord)),
|
||||
);
|
||||
|
||||
yield self.env.EMAIL_SERVICE.sendMail({
|
||||
to: 'geoff@seemueller.io',
|
||||
plaintextMessage: `WEBSITE CONTACT FORM SUBMISSION
|
||||
${firstname} ${lastname}
|
||||
${email}
|
||||
${message}`,
|
||||
});
|
||||
|
||||
return new Response('Contact record saved successfully', {
|
||||
status: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error processing contact request:', error);
|
||||
return new Response('Failed to process contact request', {
|
||||
status: 500,
|
||||
});
|
||||
}
|
||||
}),
|
||||
}));
|
3
packages/services/src/contact-service/index.ts
Normal file
3
packages/services/src/contact-service/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import ContactService from './ContactService.ts';
|
||||
|
||||
export { ContactService };
|
Reference in New Issue
Block a user