-
@ Garth
2024-03-25 18:37:25```
const buildEvent = (draft) => {
let event = {}; // Initialize the event object
let type; // Initialize the type variable
switch (draft?.type) {
case 'resource':
event = {
kind: draft?.price ? 30402 : 30023, // Determine kind based on if price is present
content: draft.content,
created_at: Math.floor(Date.now() / 1000),
tags: [
['d', draft.id],
['title', draft.title],
['summary', draft.summary],
['image', draft.image],
['t', ...draft.topics],
['published_at', Math.floor(Date.now() / 1000).toString()],
// Include price and location tags only if price is present
...(draft?.price ? [['price', draft.price], ['location', `https://plebdevs.com/resource/${draft.id}`]] : []),
]
};
type = 'resource';
break;
case 'workshop':
// Assuming workshop events have a similar structure to resources
// You can adjust the event structure and kind as necessary
event = {
kind: 30023, // Example kind for workshops
content: draft.content,
created_at: Math.floor(Date.now() / 1000),
tags: [
['d', draft.id],
['title', draft.title],
['summary', draft.summary],
['image', draft.image],
['t', ...draft.topics],
['published_at', Math.floor(Date.now() / 1000).toString()],
]
};
type = 'workshop';
break;
case 'course':
// Assuming course events have a similar structure
// Adjust as necessary for your application's logic
event = {
kind: 30023, // Example kind for courses
content: draft.content,
created_at: Math.floor(Date.now() / 1000),
tags: [
['d', draft.id],
['title', draft.title],
['summary', draft.summary],
['image', draft.image],
['t', ...draft.topics],
['published_at', Math.floor(Date.now() / 1000).toString()],
]
};
type = 'course';
break;
default:
// Handle unknown draft type or return a default structure if necessary
event = null;
type = 'unknown';
}
return { unsignedEvent: event, type }; // Return both the event and its type
};
```