This commit is contained in:
geoffsee
2025-06-25 13:20:59 -04:00
committed by Geoff Seemueller
parent 21d6c8604e
commit 554096abb2
86 changed files with 556 additions and 508 deletions

View File

@@ -0,0 +1,54 @@
import * as schema from '@open-gsio/schema';
import { Schema } from '@open-gsio/schema';
import { types, flow, getSnapshot } from 'mobx-state-tree';
export default types
.model('FeedbackStore', {})
.volatile(self => ({
env: {} as Env,
ctx: {} as ExecutionContext,
}))
.actions(self => ({
setEnv(env: Env) {
self.env = env;
},
setCtx(ctx: ExecutionContext) {
self.ctx = ctx;
},
handleFeedback: flow(function* (request: Request) {
try {
const {
feedback,
timestamp = new Date().toISOString(),
user = 'Anonymous',
} = yield request.json();
const feedbackRecord = Schema.FeedbackRecord.create({
feedback,
timestamp,
user,
});
const feedbackId = crypto.randomUUID();
yield self.env.KV_STORAGE.put(
`feedback:${feedbackId}`,
JSON.stringify(getSnapshot(feedbackRecord)),
);
yield self.env.EMAIL_SERVICE.sendMail({
to: 'geoff@seemueller.io',
plaintextMessage: `NEW FEEDBACK SUBMISSION
User: ${user}
Feedback: ${feedback}
Timestamp: ${timestamp}`,
});
return new Response('Feedback saved successfully', { status: 200 });
} catch (error) {
console.error('Error processing feedback request:', error);
return new Response('Failed to process feedback request', {
status: 500,
});
}
}),
}));

View File

@@ -0,0 +1,3 @@
import FeedbackService from './FeedbackService';
export { FeedbackService };