Skip to content

Commit

Permalink
add funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarFang416 committed Mar 22, 2024
1 parent 418ae8f commit 7450113
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 17 deletions.
64 changes: 64 additions & 0 deletions picea/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions picea/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@aws-sdk/client-chime-sdk-meetings": "^3.535.0",
"aws-sdk": "^2.1583.0",
"serverless": "^3.38.0"
}
Expand Down
16 changes: 16 additions & 0 deletions picea/backend/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ functions:
path: storage
method: get
cors: true
dynamo:
handler: services/DynamoDB.getAllCounsellers
description: get counsellers
events:
- http:
path: counsellers
method: get
cors: true
db:
handler: services/db.database
description: Database
Expand All @@ -87,6 +95,14 @@ functions:
- http:
path: database
method: get
meeting:
handler: services/chime.createMeetings
description: create meeting
events:
- http:
path: meeting
method: get
cors: true

# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
Expand Down
55 changes: 38 additions & 17 deletions picea/backend/services/DynamoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const meeting = "meeting"
const counsellor = "counsellor"

// Retrieve meeting from the meeting table by meeting title
const getMeeting = async (id) => {
module.exports.getMeeting = async (id) => {
const result = await ddb.getItem({
TableName: meeting,
Key: {
Expand All @@ -27,7 +27,7 @@ const getMeeting = async (id) => {
};

// Add meeting in the meeting table
const putMeeting = async (id, meetingInfo) => {
module.exports.putMeeting = async (id, meetingInfo) => {
await ddb.putItem({
TableName: meeting,
Item: {
Expand All @@ -40,7 +40,7 @@ const putMeeting = async (id, meetingInfo) => {
};

//returns a list of participants in the given meeting
const getMeetingParticipants = async (id, participantId) => {
module.exports.getMeetingParticipants = async (id, participantId) => {
const result = await ddb.getItem({
TableName: meeting,
Key: {
Expand All @@ -53,7 +53,7 @@ const putMeeting = async (id, meetingInfo) => {
};

//returns the id of the counsellor of the meeting
const getMeetingCounsellor = async (id, counsellorId) => {
module.exports.getMeetingCounsellor = async (id, counsellorId) => {
const result = await ddb.getItem({
TableName: meeting,
Key: {
Expand All @@ -69,7 +69,7 @@ const putMeeting = async (id, meetingInfo) => {
};

//add a participant to a meeting
const addParticipantToMeeting = async (meetingID, participantId) => {
module.exports.addParticipantToMeeting = async (meetingID, participantId) => {
await ddb.UpdateItem({
TableName: meeting,
Key: {
Expand All @@ -85,7 +85,7 @@ const putMeeting = async (id, meetingInfo) => {
};


const addCounsellorToMeeting = async (meetingID, counsellorId) => {
module.exports.addCounsellorToMeeting = async (meetingID, counsellorId) => {
await ddb.UpdateItem({
TableName: meeting,
Key: {
Expand All @@ -101,7 +101,7 @@ const putMeeting = async (id, meetingInfo) => {
};

//return a list of counsellor_id that fits within the participants' desired avaliability
const findAvaliableCounsellor = async (participantStartTime) => {
module.exports.findAvaliableCounsellor = async (participantStartTime) => {
await ddb.scan({
TableName: counsellor,
FilterExpression: 'endTime > :startTime', // Define your condition using a numerical comparison operator
Expand All @@ -112,7 +112,7 @@ const putMeeting = async (id, meetingInfo) => {
return result.Item ? result.Item.counsellor_id : null;
};

const getCounsellorName = async (id) => {
module.exports.getCounsellorName = async (id) => {
const result = await ddb.getItem({
TableName: counsellor,
Key: {
Expand All @@ -124,13 +124,34 @@ const putMeeting = async (id, meetingInfo) => {
return result.Item ? JSON.parse(result.Item.name.SS) : null;
};

module.exports.database = async (
id,
meetingInfo,
participantId,
counsellorId,
participantStartTime
) => {
getMeeting, putMeeting, getMeetingParticipants, getMeetingCounsellor, addParticipantToMeeting,
addCounsellorToMeeting, findAvaliableCounsellor, getCounsellorName

export const scanTable = async (tableName) => {
const params = {
TableName: tableName,
};

const scanResults = [];
let items;
do{
items = await documentClient.scan(params).promise();
items.Items.forEach((item) => scanResults.push(item));
params.ExclusiveStartKey = items.LastEvaluatedKey;
}while(typeof items.LastEvaluatedKey !== "undefined");

return scanResults;
};

module.exports.getAllCounsellers = async () => {
return scanTable(counsellor);
}

// module.exports.database = async (
// id,
// meetingInfo,
// participantId,
// counsellorId,
// participantStartTime
// ) => {
// getMeeting, putMeeting, getMeetingParticipants, getMeetingCounsellor, addParticipantToMeeting,
// addCounsellorToMeeting, findAvaliableCounsellor, getCounsellorName
// };
43 changes: 43 additions & 0 deletions picea/backend/services/chime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { ChimeSDKMeetings } = require('@aws-sdk/client-chime-sdk-meetings');

const chimeSDKMeetings = new ChimeSDKMeetings({ region: 'us-east-1' });

function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = (Math.random() * 16) | 0,
v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}

module.exports.createMeetings = async (event, context) => {
const title = 'default-meeting';
const userId = 'default-user';

const request = {
ClientRequestToken: uuid(),
MediaRegion: 'us-east-1',
ExternalMeetingId: title.substring(0, 64),
};
console.info('Creating new meeting before joining: ' + JSON.stringify(request));
const meetingInfo = await chimeSDKMeetings.createMeeting(request);
console.log(meetingInfo)

const { Attendee } = await chimeSDKMeetings.createAttendee({
MeetingId: meetingInfo.Meeting.MeetingId,
ExternalUserId: userId,
});

let returnObject = {
statusCode: 200,
headers: {
"access-control-allow-origin": "*"
},
body: JSON.stringify({
meeting: meetingInfo,
attendee: Attendee
})
};

return returnObject;
}

0 comments on commit 7450113

Please sign in to comment.