-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bee93d0
commit 14ec228
Showing
8 changed files
with
210 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
PORT=8000 | ||
MONGODB_URI=mongodb+srv://PreshyJones:confidence@myfirstcluster-2ekpt.mongodb.net/dinner?retryWrites=true&w=majority | ||
JWT_EXPIRES_IN="90d" | ||
JWT_SECRET= "ejgesgfyjehfvsyukaffrg" | ||
REFRESH_TOKEN_SECRET="ejgesgfyjehfvsyukaffrg" | ||
NODE_ENV=development | ||
SENDGRID_API_KEY=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 | ||
GOOGLE_CLIENT_ID="942349562307-ldd3b7317ih6nskr99gn81r73jitm927.apps.googleusercontent.com" | ||
GOOGLE_CLIENT_SECRET="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" | ||
SERVER_ROOT_URI='http://localhost:8000/api/v1/auth/google/token' | ||
UI_ROOT_URI='http://localhost:3000' | ||
COOKIE_NAME='auth_token' | ||
INVITATION_TOKEN_SECRET="boomshakalaka" | ||
CREDENTIALS='{"type": "service_account","project_id": "confident-facet-364012","private_key_id": "1f817510d3efade14b09de482b156c00bccf6e21","private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCr2/kpAYU2YUuR\nexWuEI+z83T+DbNfeRJxo4MS/7ko17Xav16REGYd3SoHqnWy6lUQ02Enml4wp4eC\nmnaHicsLoqwYE6NCVbBMwFvXsv6JK3vwiuL94N1FGGalRG47WW4kp7XqM4KxjhN6\ntfGnMs+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3pZTDuax0C5Wp77g8qc86rmUvlCRAS3+XL6hAoGAM8yX\nuO6mQAuCBDTQyJnwS2rkiJA5ioKctcvYINJ0ydjtT1NPEDHRQ1Dn4h1QFWzcklDh\nsI95SV0R3LQsuBZ4tz1yRsJZ6vj3E5hh0dZSxRLjnVesXFEMXkHxUbvE/2wk7yHe\nzf7d9OkOXvaFB/zrFAYSIrW3pQygdUVbX182yVECgYAlhtBwb2T/cXezCQqONB/a\nyX6a5X3PwG1JEoBXXlrXb2FsX64vDdcQIuHQGhCSQ8wYr4HloIxwbqtdOt2nn3x7\nVBADOS+33hjwq5hIH7238UqGTl12nSYHxS2Q2m3GLlEX9ys5Zf8dvOLS4t933OJz\nC0rjmj/8zR8368XA2X8QpQ==\n-----END PRIVATE KEY-----\n","client_email": "i123456@confident-facet-364012.iam.gserviceaccount.com","client_id": "102254133935705883736","auth_uri": "https://accounts.google.com/o/oauth2/auth","token_uri": "https://oauth2.googleapis.com/token","auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/i123456%40confident-facet-364012.iam.gserviceaccount.com"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const expressAsyncHandler = require('express-async-handler'); | ||
const services = require('../services'); | ||
|
||
const { google } = require('googleapis'); | ||
require('dotenv').config(); | ||
|
||
// Provide the required configuration | ||
const CREDENTIALS = | ||
// JSON.parse( | ||
process.env.CREDENTIALS; | ||
// ); | ||
|
||
// Google calendar API settings | ||
const SCOPES = 'https://www.googleapis.com/auth/calendar'; | ||
const calendar = google.calendar({ version: 'v3' }); | ||
|
||
const auth = new google.auth.JWT( | ||
CREDENTIALS.client_email, | ||
null, | ||
CREDENTIALS.private_key, | ||
SCOPES | ||
); | ||
|
||
// Insert Event Into Controller | ||
const insertCalendar = expressAsyncHandler(async (req, res, next) => { | ||
try { | ||
let response = await calendar.events.insert({ | ||
auth: auth, | ||
calendarId: req.body.calendarId, | ||
resource: req.body.event, | ||
}); | ||
|
||
if (response['status'] == 200 && response['statusText'] === 'OK') { | ||
const message = 'Successfully added event into calendar'; | ||
return services.newEventToken({}, 'success', message, res); | ||
} else { | ||
return services.createSendToken({}, 'error', response['statusText'], res); | ||
} | ||
} catch (error) { | ||
console.log(`Error at insertEvent --> ${error}`); | ||
return services.createSendToken({}, 'error', error, res); | ||
} | ||
}); | ||
|
||
// Get Event in Calendar | ||
const getCalendar = expressAsyncHandler(async (req, res, next) => { | ||
try { | ||
let response = await calendar.events.list({ | ||
auth: auth, | ||
calendarId: req.body.calendarId, | ||
timeMin: req.body.dateTimeStart, | ||
timeMax: req.body.dateTimeEnd, | ||
timeZone: 'Asia/Kolkata', | ||
}); | ||
|
||
console.log(response); | ||
|
||
let items = response['data']['items']; | ||
const message = 'Successfully fetched events in calendar'; | ||
return services.newEventToken(items, 'success', message, res); | ||
} catch (error) { | ||
console.log(`Error at getEvents --> ${error}`); | ||
return services.createSendToken({}, 'error', error, res); | ||
} | ||
}); | ||
|
||
// Delete Event in Calendar | ||
const deleteCalendar = expressAsyncHandler(async (req, res, next) => { | ||
try { | ||
let response = await calendar.events.delete({ | ||
auth: auth, | ||
calendarId: req.body.calendarId, | ||
eventId: req.body.eventId, | ||
}); | ||
|
||
if (response.data === '') { | ||
const message = 'Successfully deleted event in calendar'; | ||
return services.newEventToken({}, 'success', message, res); | ||
} else { | ||
return services.createSendToken( | ||
{}, | ||
'error', | ||
'Something ent wrong hilt deleting', | ||
res | ||
); | ||
} | ||
} catch (error) { | ||
console.log(`Error at deleteEvent --> ${error}`); | ||
return services.createSendToken({}, 'error', error, res); | ||
} | ||
}); | ||
|
||
module.exports = { | ||
getCalendar, | ||
deleteCalendar, | ||
insertCalendar, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters