Skip to content

Commit

Permalink
chore: create and add appscript files
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakSKumar committed Sep 15, 2024
1 parent c619654 commit 593fa82
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 32 deletions.
35 changes: 35 additions & 0 deletions appscript/Apis.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function sendEdits(payload) {
const options = {
method: "POST",
contentType: "application/json",
payload: JSON.stringify(payload),
muteHttpExceptions: true,
};

const url = getConfig().web_service_url;

try {
const response = UrlFetchApp.fetch(url, options);
logMessage("Updated Successfully " + error.message);
} catch (error) {
logMessage("Error sending updates to server: " + error.message);
}
}

function getEdits(payload) {
const options = {
method: "POST",
contentType: "application/json",
payload: JSON.stringify(payload),
muteHttpExceptions: true,
};

const url = getConfig().web_service_url;

try {
const response = UrlFetchApp.fetch(url, options);
logMessage("Updated Successfully " + error.message);
} catch (error) {
logMessage("Error sending updates to server: " + error.message);
}
}
59 changes: 59 additions & 0 deletions appscript/Code.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function doGet(e) {
return ContentService.createTextOutput('GET request received');
}

function doPost(e) {
var params = JSON.parse(e.postData.contents);
Logger.log(params)
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
Logger.log(sheet)
sheet.getRange(params.row, 1).setValue(params.value);
return ContentService.createTextOutput('POST request received and processed');
}

function onEdit(e) {
const sheet = e.source.getActiveSheet();
const range = e.range;

const cellLetters = ['A', 'B', 'C', 'D', 'E'];
const updatedCells = [];

const startColumn = range.getColumn();
const endColumn = startColumn + range.getNumColumns() - 1;

if (endColumn < 1 || startColumn > 5) return;

const colStart = Math.max(startColumn, 1);
const colEnd = Math.min(endColumn, 5);

const relevantRange = sheet.getRange(range.getRow(), colStart, range.getNumRows(), colEnd - colStart + 1);

for (let i = 0; i < relevantRange.getNumRows(); i++) {
for (let j = 0; j < relevantRange.getNumColumns(); j++) {
const cellRange = relevantRange.getCell(i + 1, j + 1);
const cellLetter = cellRange.getA1Notation().charAt(0);

if (cellLetters.includes(cellLetter)) {
const oldValue = e.oldValue ? e.oldValue[i * relevantRange.getNumColumns() + j] : '';
const newValue = cellRange.getValue();

if (oldValue || newValue !== '') {
updatedCells.push({
cell: cellRange.getA1Notation(),
oldValue: oldValue,
newValue: newValue
});
}
}
}
}

if (updatedCells.length > 0) {
const logEntry = {
timestamp: new Date().toISOString(),
updatedCells: updatedCells
};

Logger.log(JSON.stringify(logEntry, null, 2));
}
}
66 changes: 66 additions & 0 deletions appscript/Utils.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
function doGet(e) {
return ContentService.createTextOutput("GET request received");
}

function doPost(e) {
var params = JSON.parse(e.postData.contents);
Logger.log(params);
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
Logger.log(sheet);
sheet.getRange(params.row, 1).setValue(params.value);
return ContentService.createTextOutput("POST request received and processed");
}

function onEdit(e) {
const sheet = e.source.getActiveSheet();
const range = e.range;

const cellLetters = ["A", "B", "C", "D", "E"];
const updatedCells = [];

const startColumn = range.getColumn();
const endColumn = startColumn + range.getNumColumns() - 1;

if (endColumn < 1 || startColumn > 5) return;

const colStart = Math.max(startColumn, 1);
const colEnd = Math.min(endColumn, 5);

const relevantRange = sheet.getRange(
range.getRow(),
colStart,
range.getNumRows(),
colEnd - colStart + 1
);

for (let i = 0; i < relevantRange.getNumRows(); i++) {
for (let j = 0; j < relevantRange.getNumColumns(); j++) {
const cellRange = relevantRange.getCell(i + 1, j + 1);
const cellLetter = cellRange.getA1Notation().charAt(0);

if (cellLetters.includes(cellLetter)) {
const oldValue = e.oldValue
? e.oldValue[i * relevantRange.getNumColumns() + j]
: "";
const newValue = cellRange.getValue();

if (oldValue || newValue !== "") {
updatedCells.push({
cell: cellRange.getA1Notation(),
oldValue: oldValue,
newValue: newValue,
});
}
}
}
}

if (updatedCells.length > 0) {
const logEntry = {
timestamp: new Date().toISOString(),
updatedCells: updatedCells,
};

Logger.log(JSON.stringify(logEntry, null, 2));
}
}
10 changes: 10 additions & 0 deletions appscript/appscript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"timeZone": "Asia/Kolkata",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"webapp": {
"executeAs": "USER_DEPLOYING",
"access": "ANYONE_ANONYMOUS"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions app/app.ts → webservice/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import express, { Express } from 'express';
import { MyServer } from '@root/setup/setupServer';
import { config } from '@root/config';
import { MyServer } from '@/setup/setupServer';
import { config } from '@/config';

class Application {
public start(): void {
this.loadConfig();
Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 9 additions & 10 deletions package.json → webservice/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"name": "typescript_nodejs_express_template",
"name": "stackit-hiring-assignment",
"version": "1.0.0",
"description": "",
"main": "app.js",
"main": "build/app.js",
"scripts": {
"start": "NODE_ENV=production pm2 start ./build/src/app.js -i 5 --attach --watch | ./node_modules/.bin/bunyan",
"dev": "nodemon -r tsconfig-paths\\register src\\app.ts | .\\node_modules\\.bin\\bunyan",
"lint": "eslint .. --ext .ts",
"lint:fix": "eslint .. --ext .ts --fix",
"prettier:check": "prettier --check src/**/*.{ts,json}",
"prettier:fix": "prettier --write src/**/*.{ts,json}",
"start": "NODE_ENV=production pm2 start ./build/app.js -i 5 --attach --watch | bunyan",
"dev": "nodemon -r tsconfig-paths\\register app.ts | .\\node_modules\\.bin\\bunyan",
"lint": "eslint app --ext .ts",
"lint:fix": "eslint app --ext .ts --fix",
"prettier:check": "prettier --check app/**/*.{ts,json}",
"prettier:fix": "prettier --write app/**/*.{ts,json}",
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json"
},
"keywords": [],
"author": "Sarthak S Kumar",
"license": "MIT",
"dependencies": {
"@bull-board/api": "^5.21.6",
"@bull-board/express": "^5.21.6",
Expand All @@ -29,7 +28,6 @@
"hpp": "^0.2.3",
"http-status-codes": "^2.2.0",
"mysql2": "^3.11.2",
"nodemon": "^3.1.4",
"redis": "^4.6.7",
"typescript": "^4.9.5",
"typescript-transform-paths": "^3.4.6"
Expand All @@ -41,6 +39,7 @@
"@types/express": "^4.17.17",
"@types/hpp": "^0.2.2",
"eslint": "^8.35.0",
"nodemon": "^3.1.4",
"prettier": "^2.8.8",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.7",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml → webservice/pnpm-lock.yaml

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

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from 'express';
import HTTP_STATUS from 'http-status-codes';
import { userQueue } from 'app/src/workers/user.worker';
import { userQueue } from '@/workers/user.worker';

export class DBCRUDController {
public async read(req: Request, res: Response): Promise<void> {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/src/routes.ts → webservice/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Application } from 'express';
import { DBCRUDRoutes } from 'app/src/routes/dbcrud.routes';
import { DBCRUDRoutes } from '@/routes/dbcrud.routes';
import { serverAdapter } from './setup/setupBullBoard';

const BASE_PATH = '/api/';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express, { Router } from 'express';
import { DBCRUDController } from 'app/src/controllers/dbcrud.controller';
import { DBCRUDController } from '@/controllers/dbcrud.controller';

class CRUDRoutes {
private router: Router;
Expand Down
2 changes: 1 addition & 1 deletion app/src/routes/index.ts → webservice/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Application } from 'express';
import { DBCRUDRoutes } from 'app/src/routes/dbcrud.routes';
import { DBCRUDRoutes } from '@/routes/dbcrud.routes';
import { serverAdapter } from '../setup/setupBullBoard';

const BASE_PATH = '/api/';
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ExpressAdapter } from '@bull-board/express';
const { createBullBoard } = require('@bull-board/api');
const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter');

import { userQueue } from 'app/src/workers/user.worker';
import { userQueue } from '@/workers/user.worker';

export const serverAdapter = new ExpressAdapter();
serverAdapter.setBasePath('/queues');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as process from 'process';
import Logger from 'bunyan';
import { config } from '@root/config';
import { config } from '@/config';

const mysql = require('mysql2');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import HTTP_STATUS from 'http-status-codes';
import Logger from 'bunyan';
import 'express-async-errors';
import * as process from 'process';
import { config } from '@root/config/config';
import applicationRoutes from 'app/src/routes';
import { config } from '@/config';
import applicationRoutes from '@/routes';
import { IErrorResponse, CustomError } from '../helpers/error-handler';

const log: Logger = config.createLogger('server');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Queue, Worker } from 'bullmq'; // Import Queue from bullmq
import Logger from 'bunyan';
import { config } from '@root/config/config';
import { config } from '@/config';

const log: Logger = config.createLogger('userWorker');

// Create a specific queue for user work
export const userQueue = new Queue('userQueue', {
connection: {
host: config.REDIS_HOST,
Expand Down
8 changes: 1 addition & 7 deletions tsconfig.json → webservice/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@
}
],
"paths": {
"@auth/*": ["app/src/features/auth/*"],
"@user/*": ["app/src/features/user/*"],
"@global/*": ["app/src/shared/globals/*"],
"@service/*": ["app/src/services/*"],
"@socket/*": ["app/src/shared/sockets/*"],
"@worker/*": ["app/src/workers/*"],
"@root/*": ["app/src/*"]
"@/*": ["src/*"],
}
}
}

0 comments on commit 593fa82

Please sign in to comment.