-
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.
[main] - did the update local function
- Loading branch information
Showing
16 changed files
with
219 additions
and
64 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIiwiaXNzIjoiaHR0cHM6Ly9pb3NpZnYuZXUuYXV0aDAuY29tLyJ9..OdkeuJJdkwkc60Y9.ENmMJVqfBkPsPKWw6bgi5Hbv-VHDNq0j8b2gZmksoNp3xKstpqzei5qLsk7_uQTLTKCnV4YlbEsetxG584Datrjoqo_uC1pGSEnkjlpezo7bgmBSnF6shaI4AwbJ3ooSV2wuoFZRYDSrvjS-SQzSQDIv8VuS2qCMY0s-nDOiKkUKXdUDzZIa9wCiNxqT1Wn112p3IgTIueFnePZTjm0BGJkICsv2gDph867QZV0CfvhvV0kTtXBpgLaPHKpEbMM2_MmF06bEN_fGwi_hH6hQYA.7b6ZDoHPVvP0OxLdGt5DvQ" | ||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"payload\": \"empty\"}" | ||
} | ||
|
||
} |
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,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"payload\": \"empty\"}" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIiwiaXNzIjoiaHR0cHM6Ly9pb3NpZnYuZXUuYXV0aDAuY29tLyJ9..NY-9HQYiM8YidKN-.ZW1vgY3HFABgf8j7tU7kRB-UvG2E6XNbzMCTevX3W8HCLXetz5ZgdliOEsDioC0oZR9ZhjJ92lCR0FzKgD2ZZ0tPd_ymqmQeHvvk1Bbq7lVZncTAVGhtqZdIACzbisOupCDYlZa_1YzN1nelBfjIPLYSlfLFRQmdyCDCN-VvR5DcpvoYXrCnpte3xSHVyBZOrUm2_F0IxiaDxMfnpzQZJyIBB6Nyep3LAOA5hOGHNIZA5ft80EbhLUp07qsbSF9pGU4WpXKmhwenr_oc1TEP-w.XPPQRq2Vl3J67JAjsRuHNA" | ||
|
||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"origin\": \"Amsterdam\",\"destination\": \"Berlin\"}" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"origin\": \"Amsterdam\",\"destination\": \"Berlin\"}" | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIiwiaXNzIjoiaHR0cHM6Ly9pb3NpZnYuZXUuYXV0aDAuY29tLyJ9..OdkeuJJdkwkc60Y9.ENmMJVqfBkPsPKWw6bgi5Hbv-VHDNq0j8b2gZmksoNp3xKstpqzei5qLsk7_uQTLTKCnV4YlbEsetxG584Datrjoqo_uC1pGSEnkjlpezo7bgmBSnF6shaI4AwbJ3ooSV2wuoFZRYDSrvjS-SQzSQDIv8VuS2qCMY0s-nDOiKkUKXdUDzZIa9wCiNxqT1Wn112p3IgTIueFnePZTjm0BGJkICsv2gDph867QZV0CfvhvV0kTtXBpgLaPHKpEbMM2_MmF06bEN_fGwi_hH6hQYA.7b6ZDoHPVvP0OxLdGt5DvQ" | ||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"name\": \"Iosif\"}" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"name\": \"Iosif\"}" | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIiwiaXNzIjoiaHR0cHM6Ly9pb3NpZnYuZXUuYXV0aDAuY29tLyJ9..OdkeuJJdkwkc60Y9.ENmMJVqfBkPsPKWw6bgi5Hbv-VHDNq0j8b2gZmksoNp3xKstpqzei5qLsk7_uQTLTKCnV4YlbEsetxG584Datrjoqo_uC1pGSEnkjlpezo7bgmBSnF6shaI4AwbJ3ooSV2wuoFZRYDSrvjS-SQzSQDIv8VuS2qCMY0s-nDOiKkUKXdUDzZIa9wCiNxqT1Wn112p3IgTIueFnePZTjm0BGJkICsv2gDph867QZV0CfvhvV0kTtXBpgLaPHKpEbMM2_MmF06bEN_fGwi_hH6hQYA.7b6ZDoHPVvP0OxLdGt5DvQ" | ||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"query\": \"Dam Square Ams\"}" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"query\": \"Dam Square Ams\"}" | ||
} |
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIiwiaXNzIjoiaHR0cHM6Ly9pb3NpZnYuZXUuYXV0aDAuY29tLyJ9.._olX-PXcTyZ2IrCG.2pt3kxAUemOXZf0KbkHxDnDswMk75Pgj5ewP_ig0faHy_Kxc0OvNQg8gdmSLlDweQpos9kyPS612C2hHvf5AvrtQh3s2J4aFDGnOoJ8ozymFtTa4m12qwimpK31DyGYno_SJ89wL12pdcQ71eB-N3K5RjDZbg07UGymGs_bXFSVmv929MX_U0XiVBSIJenOnuXg9cyArkDgJa4E5nDkmrf3fVMwJRI3F7-2bL41Upyaycd5fmpJ-HUbwt3vfgBqXO9ncuEIWQMt3J6-u5dv3nw.RKB1-pYhLxZCQL-CWKyfmg" | ||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"payload\": \"empty\"}" | ||
} | ||
|
||
} |
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,7 @@ | ||
{ | ||
"headers": { | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer the_token_goes_here" | ||
}, | ||
"body": "{\"payload\": \"empty\"}" | ||
} |
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,58 @@ | ||
import { DynamoDBClient, ScanCommand } from '@aws-sdk/client-dynamodb' | ||
import { DynamoDBDocumentClient, PutCommand } from '@aws-sdk/lib-dynamodb' | ||
import { TABLE_NAME_USAGE_LOG } from '@utils/constants' | ||
import {} from '@aws-sdk/lib-dynamodb' | ||
|
||
// const dynamoDbClient = new DynamoDBClient() | ||
// const dynamoDbDocumentClient = DynamoDBDocumentClient.from(dynamoDbClient) | ||
|
||
async function getMonthlyCount(): Promise<number> { | ||
const dynamoDbDocumentClient = DynamoDBDocumentClient.from(new DynamoDBClient()) | ||
const currentDate = new Date() | ||
const currentMonth = currentDate.getMonth() + 1 // Months are 0-based, so adding 1 | ||
const currentYear = currentDate.getFullYear() | ||
let beginFilter: string | ||
if (currentMonth < 10) { | ||
beginFilter = `${currentYear}-0${currentMonth}` | ||
} else { | ||
beginFilter = `${currentYear}-${currentMonth}` | ||
} | ||
|
||
const params = { | ||
TableName: TABLE_NAME_USAGE_LOG, | ||
FilterExpression: 'begins_with(CreatedAt, :prefix)', | ||
ExpressionAttributeValues: { | ||
':prefix': { S: beginFilter }, | ||
}, | ||
} | ||
|
||
try { | ||
const data = await dynamoDbDocumentClient.send(new ScanCommand(params)) | ||
return data.Count || 0 // Return 0 if Count is undefined | ||
} catch (error) { | ||
console.error('Unable to scan the table. Error:', error) | ||
return 0 // Return 0 if there's an error | ||
} | ||
} | ||
|
||
async function increaseMonthlyCount(event) { | ||
const dynamoDbDocumentClient = DynamoDBDocumentClient.from(new DynamoDBClient()) | ||
const timestamp = new Date().toISOString() // Convert Date to ISO string | ||
const params = { | ||
TableName: TABLE_NAME_USAGE_LOG, | ||
Item: { | ||
CreatedAt: timestamp, | ||
User: event.user.nickname, | ||
Data: event.body, | ||
}, | ||
} | ||
|
||
try { | ||
await dynamoDbDocumentClient.send(new PutCommand(params)) | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
} | ||
|
||
export default getMonthlyCount | ||
increaseMonthlyCount |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
require('dotenv').config() | ||
|
||
// List of paths to the mock.json files | ||
const filePaths = [ | ||
path.join(__dirname, 'src/functions/authentication/mock.json'), | ||
path.join(__dirname, 'src/functions/direction/mock.json'), | ||
path.join(__dirname, 'src/functions/healthcheck/mock.json'), | ||
path.join(__dirname, 'src/functions/location/mock.json'), | ||
path.join(__dirname, 'src/functions/statistics/mock.json'), | ||
] | ||
|
||
// Retrieve the new token from the CLI argument or .env file | ||
const newToken = process.argv[2] || process.env.AUTH0_TOKEN | ||
|
||
if (!newToken) { | ||
console.error('AUTH0_TOKEN is not defined in the .env file') | ||
process.exit(1) | ||
} | ||
|
||
const authorizationHeaderValue = 'Bearer ' + newToken | ||
|
||
// Function to update a single mock.json file | ||
const updateAuthorizationToken = (filePath) => { | ||
fs.readFile(filePath, 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(`Error reading file at ${filePath}:`, err) | ||
return | ||
} | ||
|
||
try { | ||
// Parse the JSON data | ||
const jsonData = JSON.parse(data) | ||
|
||
// Update the Authorization key with the new token | ||
jsonData.headers.Authorization = authorizationHeaderValue | ||
|
||
// Convert the JSON object back to a string | ||
const updatedJsonData = JSON.stringify(jsonData, null, 2) | ||
|
||
// Write the updated JSON back to the file | ||
fs.writeFile(filePath, updatedJsonData, 'utf8', (err) => { | ||
if (err) { | ||
console.error(`Error writing file at ${filePath}:`, err) | ||
} else { | ||
console.log(`Authorization token updated successfully in ${filePath}`) | ||
} | ||
}) | ||
} catch (parseError) { | ||
console.error(`Error parsing JSON in file at ${filePath}:`, parseError) | ||
} | ||
}) | ||
} | ||
|
||
// Iterate over each file path and update the authorization token | ||
filePaths.forEach(updateAuthorizationToken) |