From 37847346bd602c223a17b1ef3765d3de138a0072 Mon Sep 17 00:00:00 2001 From: erikajledesma Date: Sun, 12 Nov 2023 12:12:09 -0800 Subject: [PATCH] put account files back into account folder --- src/{ => account}/IUserSchema.ts | 0 src/{ => account}/account.ts | 0 src/{ => account}/config.ts | 0 src/{ => account}/index.ts | 0 src/tests/Account.test.tsx | 85 -------------------------------- 5 files changed, 85 deletions(-) rename src/{ => account}/IUserSchema.ts (100%) rename src/{ => account}/account.ts (100%) rename src/{ => account}/config.ts (100%) rename src/{ => account}/index.ts (100%) delete mode 100644 src/tests/Account.test.tsx diff --git a/src/IUserSchema.ts b/src/account/IUserSchema.ts similarity index 100% rename from src/IUserSchema.ts rename to src/account/IUserSchema.ts diff --git a/src/account.ts b/src/account/account.ts similarity index 100% rename from src/account.ts rename to src/account/account.ts diff --git a/src/config.ts b/src/account/config.ts similarity index 100% rename from src/config.ts rename to src/account/config.ts diff --git a/src/index.ts b/src/account/index.ts similarity index 100% rename from src/index.ts rename to src/account/index.ts diff --git a/src/tests/Account.test.tsx b/src/tests/Account.test.tsx deleted file mode 100644 index e6eb0031..00000000 --- a/src/tests/Account.test.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import express from "express"; -import { IUserSchema } from "../IUserSchema"; -// import cors from "cors"; -import { MongoClient } from "mongodb"; -import { config } from "../config"; - -// Information that allows microservice to talk with MongoDB -// USR (username), PSW (password), CLUS (cluster), DB (database) are defined before running docker container -export const USR = config.mongodb.username; -export const PSW = config.mongodb.password; -export const CLUS = config.mongodb.clustername; -export const DB = config.mongodb.database; -export const COL = config.mongodb.collection; - -// Information about the microservice -export const MICROSERVICE = config.microservice.account; -export const PORT = config.microservice.port; - -// URL to mongoDB cluster -export const URL = `mongodb+srv://${USR}:${PSW}@${CLUS}.cgornhw.mongodb.net/Luminosity`; - -// Creates an Express application -export const app = express(); - -// Single Routing -export const router = express.Router(); - -// Mongo Client object -export const MONGO_CLIENT = new MongoClient(URL); - -// Connect to the Atlas cluster -// export async function connect(): Promise { -// try { -// await MONGO_CLIENT.connect(); -// console.log("Successfully connected to MongoDB."); -// return true; -// } catch (err) { -// console.error("Error connecting to MongoDB " + err); -// return false; -// } -// } - -export async function registerAccount(req: any, res: any): Promise { - try { - // Create a new document - let accountDocument: IUserSchema = { - creationDate: { - value: Date.now() - }, - deletionDate: { - value: Date.now() - }, - lastUpdated: { - value: Date.now() - }, - email: { - value: req.body.email, - }, - name: { - value: req.body.name, - }, - devicesLinked: { - value: {} - } - }; - - // Pick database to connect to with mongo client - const mongo_db = MONGO_CLIENT.db(DB); - - // Reference the "accounts" collection in the specified database - const col = mongo_db.collection(COL); - - // Insert the document into the specified collection - await col.insertOne(accountDocument); - console.log("Account registered successfully"); - -// Find and return the document - const filter = { "name.last": "Turing" }; - const document = await col.findOne(filter); - console.log("Document found:\n" + JSON.stringify(document)); //this was previously commented out - } catch (err: any) { - console.log("Error " + err.stack); - console.log("Response " + res); - } -} \ No newline at end of file