Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import express from 'express';
import cors from 'cors';
import { router } from './routes/routes.mjs';

const app = express();
app.use(cors());
const PORT = process.env.PORT || 6541;

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(router);


app.listen(PORT, ()=>{
console.log(`URL: http://localhost:${PORT}`);
});
42 changes: 42 additions & 0 deletions backend/logics/CreateEvent/createEvent.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { GraphQLClient} from 'graphql-request';
import { CreateEventQuery } from './query.mjs';
import bodyParser from "body-parser";

const new_event = new CreateEventQuery();

const hasuraEndpoint = 'http://localhost:8080/v1/graphql';
const adminSecret = '123';

const client = new GraphQLClient(hasuraEndpoint, {
headers: {
'x-hasura-admin-secret': adminSecret
// 'Authorization': `Bearer ${generateJwtToken()}`
},
});



export class CreateEvent{
async create_event(req, res){
const { eventName, duration, locationType, locationDetail } = req.body;
console.log(eventName, duration, locationType, locationDetail);

try {
const data = await client.request( new_event.CreateEvent(),{
eventName,
duration: parseInt(duration),
locationType,
locationDetail
});

// console.log(data);

// res.json(data);
res.status(200).json({success:"Inset Done"});
} catch (error) {
console.error('Failed to create event:', error);
res.json({ success: false });
}

}
}
15 changes: 15 additions & 0 deletions backend/logics/CreateEvent/query.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export class CreateEventQuery{
CreateEvent(){
return `
mutation MyMutation($eventName: String!, $duration: Int!, $locationType: String!, $locationDetail: String!) {
insert_kalenview_create_events_one(object: {event_name: $eventName, duration: $duration, location_type: $locationType, location_detail: $locationDetail}) {
event_name
duration
location_type
location_detail
created_at
}
}
`;
}
}
Loading