From 7d7814667f0018b9c6771b0e750002bd57761cf6 Mon Sep 17 00:00:00 2001 From: Aaron Boyd Date: Tue, 4 Jan 2022 17:02:57 +0100 Subject: [PATCH 1/6] [FEAT] - Content endpoint Fixes #84 --- api/src/content/DidYouKnow.ts | 29 ++++++++++++++++++++ api/src/content/FeaturedArtists.ts | 34 +++++++++++++++++++++++ api/src/content/Heroes.ts | 40 ++++++++++++++++++++++++++++ api/src/content/Values.ts | 39 +++++++++++++++++++++++++++ api/src/router/content/controller.ts | 24 +++++++++++++++++ api/src/router/content/index.ts | 6 +++++ api/src/router/index.ts | 2 ++ api/src/types/index.ts | 17 ++++++++++++ 8 files changed, 191 insertions(+) create mode 100644 api/src/content/DidYouKnow.ts create mode 100644 api/src/content/FeaturedArtists.ts create mode 100644 api/src/content/Heroes.ts create mode 100644 api/src/content/Values.ts create mode 100644 api/src/router/content/controller.ts create mode 100644 api/src/router/content/index.ts diff --git a/api/src/content/DidYouKnow.ts b/api/src/content/DidYouKnow.ts new file mode 100644 index 00000000..6cc9673d --- /dev/null +++ b/api/src/content/DidYouKnow.ts @@ -0,0 +1,29 @@ +import { HomeScreenContent } from "../types"; + +export const DidYouKnow: HomeScreenContent[] = [ + { + contentType: "DidYouKnow", + image: "https://berkshares-images.imgix.net/BShare_Coins_Asset_4.png", + text: "Adopting BerkShares encourages local economic circularity—keeping more of the region’s wealth working locally. Well done for taking part!", + }, + { + contentType: "DidYouKnow", + image: "https://berkshares-images.imgix.net/BShare_Coins_Asset_5.png", + text: "Everyday citizens are increasingly seeking ways to shop locally, eat local produce, and share in community. BerkShares is a conduit for that “support local” energy!", + }, + { + contentType: "DidYouKnow", + image: "https://berkshares-images.imgix.net/BShare_Coins_Asset_6.png", + text: "As more people and businesses accept and pay through BerkShares, a larger share of local economic activity is kept working within the community. Spread the word!", + }, + { + contentType: "DidYouKnow", + image: "https://berkshares-images.imgix.net/BShare_Coins_Asset_7.png", + text: "By using blockchain technology, BerkShares offers a payment method that saves businesses on hefty processing fees. Aren’t you savvy?", + }, + { + contentType: "DidYouKnow", + image: "https://berkshares-images.imgix.net/BShare_Coins_Asset_8.png", + text: "It’s always free to accept and spend BerkShares. Encourage friends, family, and neighbors to join in and support the local economy. It’s money well spent!", + }, +]; diff --git a/api/src/content/FeaturedArtists.ts b/api/src/content/FeaturedArtists.ts new file mode 100644 index 00000000..b9c998cc --- /dev/null +++ b/api/src/content/FeaturedArtists.ts @@ -0,0 +1,34 @@ +import { HomeScreenContent } from "../types"; + +export const FeaturedArtists: HomeScreenContent[] = [ + { + contentType: "FeaturedArtists", + image: "https://berkshares-images.imgix.net/BerkShare_1-back.jpg", + textTitle: "Bart Elsbach, Reflected Connections, oil on canvas, 1999", + text: "Sheffield-based landscape painter who often depicts New England scenery. Influenced by the works of 17th and 18th Dutch Masters as well as the Hudson River School, his work has been described as a “celebration of the Berkshires.", + }, + { + contentType: "FeaturedArtists", + image: "https://berkshares-images.imgix.net/BerkShare_5-back.jpg", + textTitle: "Morgan Bulkeley, Jr., Bash Bish Gap, oil on canvas, 1976.", + text: "Mount Washington-born artist and environmental conservationist. His paintings, sculptures and other works are animated by wildlife, childhood friends, and other “floundering souls of the modern human race.", + }, + { + contentType: "FeaturedArtists", + image: "https://berkshares-images.imgix.net/BerkShare_10-back.jpg", + textTitle: "Janet Rickus, Turnips on Table, oil on panel, 1996.", + text: "West Springfield rooted painter of landscapes, portraits and still lives. Her parents operated a grocery store in West Springfield in her youth, and this early proximity to the products of the land is evident in her vibrant compositions.", + }, + { + contentType: "FeaturedArtists", + image: "https://berkshares-images.imgix.net/BerkShare_20-back.jpg", + textTitle: "Warner Friedman, June, acrylic on canvas, 1999.", + text: "Landscape artist, architect and engineer residing in Massachusetts. A lifelong fascination with mathematical precision led him to incorporate abstract geometry into an unconventional approach to land and seascape painting.", + }, + { + contentType: "FeaturedArtists", + image: "https://berkshares-images.imgix.net/BerkShare_50-back.jpg", + textTitle: "Joan Griswold, Green Shopfront, oil on linen, 1998.", + text: "Artist and teacher who calls Great Barrington home. Her richly textured scenes evoke the small town ambiance of the Berkshires as well as rural England, where she taught herself to paint.", + }, +]; diff --git a/api/src/content/Heroes.ts b/api/src/content/Heroes.ts new file mode 100644 index 00000000..15a558d9 --- /dev/null +++ b/api/src/content/Heroes.ts @@ -0,0 +1,40 @@ +import { HomeScreenContent } from "../types"; + +export const Heroes: HomeScreenContent[] = [ + { + contentType: "Heroes", + image: "https://berkshares-images.imgix.net/BerkShare_1-front.jpg", + textTitle: "The Mohican Nation", + text: "Original Native American inhabitants of these lands and waterways prior to European settlement. Their responsible stewardship of our environment recalls our obligation to respect and care for our living ecology. A township was granted to tribe members in 1736 in today’s Stockbridge and West Stockbridge. These lands were later lost to white settlement through mortgage, debt, and sometimes fraud, and the group eventually accepted an offer of removal, and today’s Stockbridge-Munsee Band is centered around a reservation in Wisconsin. They still look to the Berkshires as a part of their ancestral homeland.", + }, + { + contentType: "Heroes", + image: "https://berkshares-images.imgix.net/BerkShare_5-front.jpg", + textTitle: "W. E. B. Du Bois", + text: "Sociologist and civil rights pioneer committed to the freedom and equality of all peoples. Born in Great Barrington in 1868, Du Bois’ activities contributed to the formation of the National Association for the Advancement of Colored People. For twenty-five years he served as editor of the NAACP Magazine, The Crisis. Today, Du Bois’s boyhood homesite in the Berkshires is dedicated as a National Historic Landmark.", + }, + { + contentType: "Heroes", + image: "https://berkshares-images.imgix.net/BerkShare_50-front.jpg", + textTitle: "Norman Rockwell", + text: "Iconic 20th century American artist celebrated for his vivid and affectionate portraits of everyday life. The people and community of Stockbridge are eternally woven into Rockwell’s classic depictions. The Norman Rockwell Museum at Stockbridge is a trust dedicated to his legacy.", + }, + { + contentType: "Heroes", + image: "https://berkshares-images.imgix.net/BerkShare_20-front.jpg", + textTitle: "Herman Melville", + text: "Writer and mariner lauded for his great American novel, Moby-Dick written at Arrowhead. Melville frequented the Berkshires as a boy and, inspired by the beauty of the area, settled near Pittsfield in 1850. Written at Arrowhead farmhouse by 1851, its brilliance — with timeless reflections on human nature and environmental ethics — was not fully recognized until later. Arrowhead is today preserved as a National Historic Landmark.", + }, + { + contentType: "Heroes", + image: "https://berkshares-images.imgix.net/BerkShare_10-front.jpg", + links: [ + { + url: "https://berkshiregrown.org/", + text: "Berkshire Grown", + }, + ], + textTitle: "Robyn Van En", + text: "A pioneer of the community supported agriculture (CSA) movement in North America. Van En co-founded the forerunner to today’s Berkshire Grown. Her Indian Line Farm in South Egremont has been a model for small-scale, sustainable agriculture since 1985. Her work lives on locally and in more than 3,000 CSAs now active globally.", + }, +]; diff --git a/api/src/content/Values.ts b/api/src/content/Values.ts new file mode 100644 index 00000000..a370f31f --- /dev/null +++ b/api/src/content/Values.ts @@ -0,0 +1,39 @@ +import { HomeScreenContent } from "../types"; + +export const Values: HomeScreenContent[] = [ + { + contentType: "Values", + image: + "https://berkshares-images.imgix.net/BSHARES_UI_AssetsWell_original.tif.svg", + textTitle: "COMMUNITY", + text: "BerkShares fosters stronger community connections through personal exchanges and local trade.", + }, + { + contentType: "Values", + image: + "https://berkshares-images.imgix.net/BSHARES_UI_AssetsWheat_original.tif.svg", + textTitle: "ECONOMY", + text: "BerkShares are a tool for strengthening the local economy by prioritizing local exchange, building regional supply chain resilience.", + }, + { + contentType: "Values", + image: + "https://berkshares-images.imgix.net/BSHARES_UI_AssetsHive_original.tif.svg", + textTitle: "ECOLOGY", + text: "By encouraging people to shop locally, and businesses to procure locally, BerkShares decreases the distance of goods shipped.", + }, + { + contentType: "Values", + image: + "https://berkshares-images.imgix.net/BSHARES_UI_AssetsPhoenix_original.tif.svg", + textTitle: "SUSTAINABILITY", + text: "By promoting the local production and consumption of food and manufactured wares, using BerkShares helps nurture a sustainable future for the Berkshires.", + }, + { + contentType: "Values", + image: + "https://berkshares-images.imgix.net/BSHARES_UI_AssetsPeacock_original.tif.svg", + textTitle: "EQUITY", + text: "BerkShares strives to support a flourishing local economy for all residents, including groups structurally excluded from economic determination and regional prosperity.", + }, +]; diff --git a/api/src/router/content/controller.ts b/api/src/router/content/controller.ts new file mode 100644 index 00000000..896d6128 --- /dev/null +++ b/api/src/router/content/controller.ts @@ -0,0 +1,24 @@ +import { Request, Response } from "express"; +import { HomeScreenContent } from "src/types"; +import { httpUtils, log } from "src/utils"; +import { DidYouKnow } from "src/content/DidYouKnow"; +import { FeaturedArtists } from "src/content/FeaturedArtists"; +import { Heroes } from "src/content/Heroes"; +import { Values } from "src/content/Values"; + +const codes = httpUtils.codes; + +export async function getContent(_req: Request, res: Response): Promise { + try { + const content: HomeScreenContent[] = [ + ...DidYouKnow, + ...FeaturedArtists, + ...Heroes, + ...Values, + ]; + httpUtils.createHttpResponse(content, codes.OK, res); + } catch (err) { + log(err); + httpUtils.createHttpResponse({ message: "Server error: " + err }, 500, res); + } +} diff --git a/api/src/router/content/index.ts b/api/src/router/content/index.ts new file mode 100644 index 00000000..d4c2a064 --- /dev/null +++ b/api/src/router/content/index.ts @@ -0,0 +1,6 @@ +import express from "express"; +import * as controller from "./controller"; + +const content = express(); +content.get("/content", controller.getContent); +export default content; diff --git a/api/src/router/index.ts b/api/src/router/index.ts index b60f73ad..74e8f4bb 100644 --- a/api/src/router/index.ts +++ b/api/src/router/index.ts @@ -5,6 +5,7 @@ import stats from "./stats"; import admin from "./admin"; import businesses from "./businesses"; import health from "./health"; +import content from "./content"; const router = express(); @@ -14,5 +15,6 @@ router.use(user); router.use(stats); router.use(admin); router.use(businesses); +router.use(content); export default router; diff --git a/api/src/types/index.ts b/api/src/types/index.ts index 88d65c4d..cbf2a1e2 100644 --- a/api/src/types/index.ts +++ b/api/src/types/index.ts @@ -216,3 +216,20 @@ export type GenericDatabaseResponse = { data?: T; error?: E; }; + +export interface HomeScreenContentLink { + url: string; + text: string; +} +export interface HomeScreenContent { + contentType: + | "Pictures" + | "Heroes" + | "DidYouKnow" + | "Values" + | "FeaturedArtists"; + image: string; + links?: HomeScreenContentLink[]; + textTitle?: string; + text: string; +} From b25d514422c0e62d65165c989ef36c406cea796a Mon Sep 17 00:00:00 2001 From: Aaron Boyd Date: Tue, 4 Jan 2022 17:03:13 +0100 Subject: [PATCH 2/6] [STYLE] - Prettier --- api/src/middlewares/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/api/src/middlewares/index.ts b/api/src/middlewares/index.ts index b42037a4..de0f17f5 100644 --- a/api/src/middlewares/index.ts +++ b/api/src/middlewares/index.ts @@ -8,10 +8,9 @@ export const verifyRequest: express.RequestHandler = async ( response: express.Response, next: express.NextFunction ) => { - if(process.env.NODE_ENV=="test"){ + if (process.env.NODE_ENV == "test") { next(); - } - else{ + } else { const authHeader = request?.headers?.authorization; if (!authHeader) { response @@ -39,7 +38,7 @@ export const verifyRequest: express.RequestHandler = async ( .send({ message: "Internal error while verifying request!" }); } } - } + } }; export const mwVaildator = ( From cee2e3ce1330b758d900690ea2eb0f1d74dc7e91 Mon Sep 17 00:00:00 2001 From: Aaron Boyd Date: Mon, 10 Jan 2022 12:39:34 +0100 Subject: [PATCH 3/6] [FEAT] - Added `random` `limit` and `type` query parameters Added /content unit tests --- api/package.json | 1 + api/src/content/DidYouKnow.ts | 4 + api/src/router/content/controller.ts | 58 ++++++++++++-- api/src/test/Public.server.test.ts | 113 +++++++++++++++++++++++++-- 4 files changed, 162 insertions(+), 14 deletions(-) diff --git a/api/package.json b/api/package.json index 4e642d07..1b758162 100644 --- a/api/package.json +++ b/api/package.json @@ -20,6 +20,7 @@ "test:server": "yarn test --testPathPattern='server'", "test:dwolla": "yarn test --testPathPattern='dwolla'", "test:reports": "yarn test --testPathPattern='Reports'", + "test:public": "yarn test --testPathPattern='public'", "test:operator": "yarn test --testPathPattern='operator'", "test:auth": "yarn test --testPathPattern='APIAuthService.integration.test'", "test:db": "jest --passWithNoTests --forceExit --detectOpenHandles --testPathPattern='integration' --config=jest.db.config.js", diff --git a/api/src/content/DidYouKnow.ts b/api/src/content/DidYouKnow.ts index 6cc9673d..bf09ba64 100644 --- a/api/src/content/DidYouKnow.ts +++ b/api/src/content/DidYouKnow.ts @@ -4,16 +4,19 @@ export const DidYouKnow: HomeScreenContent[] = [ { contentType: "DidYouKnow", image: "https://berkshares-images.imgix.net/BShare_Coins_Asset_4.png", + textTitle: "Did You Know?", text: "Adopting BerkShares encourages local economic circularity—keeping more of the region’s wealth working locally. Well done for taking part!", }, { contentType: "DidYouKnow", image: "https://berkshares-images.imgix.net/BShare_Coins_Asset_5.png", + textTitle: "Did You Know?", text: "Everyday citizens are increasingly seeking ways to shop locally, eat local produce, and share in community. BerkShares is a conduit for that “support local” energy!", }, { contentType: "DidYouKnow", image: "https://berkshares-images.imgix.net/BShare_Coins_Asset_6.png", + textTitle: "Did You Know?", text: "As more people and businesses accept and pay through BerkShares, a larger share of local economic activity is kept working within the community. Spread the word!", }, { @@ -24,6 +27,7 @@ export const DidYouKnow: HomeScreenContent[] = [ { contentType: "DidYouKnow", image: "https://berkshares-images.imgix.net/BShare_Coins_Asset_8.png", + textTitle: "Did You Know?", text: "It’s always free to accept and spend BerkShares. Encourage friends, family, and neighbors to join in and support the local economy. It’s money well spent!", }, ]; diff --git a/api/src/router/content/controller.ts b/api/src/router/content/controller.ts index 896d6128..7a43266b 100644 --- a/api/src/router/content/controller.ts +++ b/api/src/router/content/controller.ts @@ -8,17 +8,61 @@ import { Values } from "src/content/Values"; const codes = httpUtils.codes; +function randomInteger(upTo: number, includingZero = true): number { + return Math.floor(Math.random() * upTo + (includingZero ? 0 : 1)); +} + +function selectContentFromSource( + sourceContent: HomeScreenContent[], + random?: number +): HomeScreenContent[] { + let selectedContent: HomeScreenContent[] = []; + + if (random) { + for (let i = 0; i < random; i++) { + if (sourceContent.length > 0) { + const index = randomInteger(sourceContent.length); + selectedContent.push(sourceContent[index]); + sourceContent.splice(index, 1); + } + } + } else selectedContent = sourceContent; + + return selectedContent; +} + export async function getContent(_req: Request, res: Response): Promise { try { - const content: HomeScreenContent[] = [ - ...DidYouKnow, - ...FeaturedArtists, - ...Heroes, - ...Values, - ]; + const limit = _req?.query?.limit; + const random = _req?.query?.random; + let type = _req?.query?.type; + + let content: HomeScreenContent[] = []; + + if (!type) { + content = [...DidYouKnow, ...FeaturedArtists, ...Heroes, ...Values]; + } else { + type = String(type).toUpperCase(); + + if (type == "DIDYOUKNOW") content = DidYouKnow; + if (type == "FEATUREDARTISTS") content = FeaturedArtists; + if (type == "HEROES") content = Heroes; + if (type == "VALUES") content = Values; + } + + content = selectContentFromSource(content, random); + + if (limit) { + content = content.slice(0, limit); + } + httpUtils.createHttpResponse(content, codes.OK, res); } catch (err) { log(err); - httpUtils.createHttpResponse({ message: "Server error: " + err }, 500, res); + httpUtils.createHttpResponse( + { message: "Server error: " + err }, + codes.SERVER_ERROR, + res + ); } } diff --git a/api/src/test/Public.server.test.ts b/api/src/test/Public.server.test.ts index 605c6603..8c974802 100644 --- a/api/src/test/Public.server.test.ts +++ b/api/src/test/Public.server.test.ts @@ -1,8 +1,6 @@ import { beforeAll, describe, it } from "@jest/globals"; import chai from "chai"; import chaiHttp from "chai-http"; -// import * as sinon from "sinon"; -// import * as aws from "../aws"; import { getApp } from "../server"; import { log } from "../utils"; import { codes } from "../utils/http"; @@ -30,13 +28,9 @@ describe("Public endpoints test", () => { }); it("it should retrieve heath data", (done) => { - // const stub = sinon - // .stub(aws, "verifyCognitoToken") - // .returns({ success: true }); chai .request(server) .get("/health") - .set("authorization", "tokeeeen") .then((res) => { expect(res).to.have.status(codes.OK); log(JSON.parse(res.text)); @@ -48,7 +42,112 @@ describe("Public endpoints test", () => { expect(res.body).to.haveOwnProperty("owner"); expect(res.body).to.haveOwnProperty("walletFactory"); expect(res.body).to.haveOwnProperty("controllerStatus"); - // expect(stub.calledOnce).to.eql(true); + done(); + }) + .catch((err) => { + done(err); + }); + }); + }); + + describe("GET /content", () => { + it("it should retrieve content data", (done) => { + chai + .request(server) + .get("/content") + .then((res) => { + expect(res).to.have.status(codes.OK); + log(JSON.parse(res.text)); + done(); + }) + .catch((err) => { + done(err); + }); + }); + + it("it should retrieve 6 pieces of random content data ", (done) => { + chai + .request(server) + .get("/content?random=6") + .then((res) => { + expect(res).to.have.status(codes.OK); + expect(res.body.length).to.equal(6); + log(JSON.parse(res.text)); + done(); + }) + .catch((err) => { + done(err); + }); + }); + + it("it should retrieve a limit of 3 pieces of content data ", (done) => { + chai + .request(server) + .get("/content?limit=3") + .then((res) => { + expect(res).to.have.status(codes.OK); + expect(res.body.length).to.equal(3); + log(JSON.parse(res.text)); + done(); + }) + .catch((err) => { + done(err); + }); + }); + + it("it should retrieve a limited set of 6 content pieces from 10 random content data ", (done) => { + chai + .request(server) + .get("/content?random=10&limit=6") + .then((res) => { + expect(res).to.have.status(codes.OK); + expect(res.body.length).to.equal(6); + log(JSON.parse(res.text)); + done(); + }) + .catch((err) => { + done(err); + }); + }); + + it("it should retrieve only Heroes type content", (done) => { + chai + .request(server) + .get("/content?type=Heroes") + .then((res) => { + expect(res).to.have.status(codes.OK); + expect(res.body.length).to.equal(5); + log(JSON.parse(res.text)); + done(); + }) + .catch((err) => { + done(err); + }); + }); + + it("it should retrieve only Heroes type content but in random order", (done) => { + chai + .request(server) + .get("/content?type=Heroes&random=5") + .then((res) => { + expect(res).to.have.status(codes.OK); + expect(res.body.length).to.equal(5); + log(JSON.parse(res.text)); + done(); + }) + .catch((err) => { + done(err); + }); + }); + + it("it should retrieve only 3 Featured Artists type content", (done) => { + chai + .request(server) + .get("/content?type=FeaturedArtists&limit=3") + .then((res) => { + expect(res).to.have.status(codes.OK); + expect(res.body.length).to.equal(3); + log(JSON.parse(res.text)); done(); }) .catch((err) => { From 3816471f9f15e530b58fdeb65866146bf8ece3bb Mon Sep 17 00:00:00 2001 From: Esraa Jbara Date: Mon, 10 Jan 2022 18:32:22 +0200 Subject: [PATCH 4/6] remove comment --- api/src/middlewares/index.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/api/src/middlewares/index.ts b/api/src/middlewares/index.ts index de0f17f5..aae6646f 100644 --- a/api/src/middlewares/index.ts +++ b/api/src/middlewares/index.ts @@ -20,11 +20,6 @@ export const verifyRequest: express.RequestHandler = async ( try { const verifyResponse = await verifyCognitoToken(authHeader); if (verifyResponse?.success) { - /** Extract user Id from token - const id = verifyResponse.token.username; - request.userId = id; - console.log(`Verified ${id} successfully`); - */ next(); } else { response From 8f6c4c0530b695d2d75dc6943b25eb46c0c2597e Mon Sep 17 00:00:00 2001 From: Esraa Jbara Date: Mon, 10 Jan 2022 18:32:56 +0200 Subject: [PATCH 5/6] fix validators --- api/src/router/admin/index.ts | 2 + api/src/router/user/index.ts | 61 ++++++++++++++++++------------- api/src/router/user/validators.ts | 13 +------ 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/api/src/router/admin/index.ts b/api/src/router/admin/index.ts index 07a2bb8b..17ffebce 100644 --- a/api/src/router/admin/index.ts +++ b/api/src/router/admin/index.ts @@ -8,11 +8,13 @@ admin.post("/admin/pause", verifyRequest, controller.adminPause); admin.post("/admin/unpause", verifyRequest, controller.adminUnpause); admin.post( "/admin/transfer/controller", + verifyRequest, validator.transferOwnerController, controller.transferControllerOwner ); admin.post( "/admin/transfer/user", + verifyRequest, validator.transferOwnerUser, controller.transferWalletOwner ); diff --git a/api/src/router/user/index.ts b/api/src/router/user/index.ts index cbb9f0dc..8a65710f 100644 --- a/api/src/router/user/index.ts +++ b/api/src/router/user/index.ts @@ -1,4 +1,5 @@ import express from "express"; +import { verifyRequest } from "src/middlewares" import * as controller from "./controller"; import * as validators from "./validators"; @@ -6,70 +7,78 @@ const user = express(); // Get and create user(s) user.get("/users", controller.getAllUsers); -user.post("/users", validators.createUser, controller.createUser); +user.post("/users", verifyRequest, validators.createUser, controller.createUser); user.get("/users/:id", validators.getUser, controller.getUser); // User dwolla info user.get("/users/email/:email", controller.getUserByEmail); // User database info // Get and create deposit(s) for a user user.get("/users/:id/deposit", validators.getUser, controller.getDeposits); -user.post("/users/:id/deposit", validators.deposit, controller.deposit); +user.post("/users/:id/deposit", verifyRequest,validators.deposit, controller.deposit); // Get and create withdrawal(s) for a user user.get("/users/:id/withdraw", validators.getUser, controller.getWithdrawals); -user.post("/users/:id/withdraw", validators.withdraw, controller.withdraw); +user.post("/users/:id/withdraw", verifyRequest,validators.withdraw, controller.withdraw); // Get and create transfer(s) for a user user.get("/users/:id/transfer", validators.getUser, controller.getTransfers); -user.post("/users/:id/transfer", validators.transfer, controller.transferTo); +user.post("/users/:id/transfer", verifyRequest, validators.transfer, controller.transferTo); // Get Dwolla iav-token for a user (via POST) -user.post("/users/:id/iav-token", validators.getUser, controller.getIAVToken); +user.post("/users/:id/iav-token", verifyRequest, validators.getUser, controller.getIAVToken); // Get funding sources for a user user.get( - "/users/:id/funding-sources", - validators.getUser, - controller.getFundingSources + "/users/:id/funding-sources", + verifyRequest, + validators.getUser, + controller.getFundingSources ); // Get and close notifications for a user user.get( - "/users/:id/notifications", - validators.getUser, - controller.getNotifications + "/users/:id/notifications", + verifyRequest, + validators.getUser, + controller.getNotifications ); + user.delete( - "/users/:id/notifications/:notificationId", - validators.notifications, - controller.closeNotification + "/users/:id/notifications/:notificationId", + verifyRequest, + validators.notifications, + controller.closeNotification ); // Add Customer account to existing Business account user.post( - "/users/:id/customer", - validators.addCustomer, - controller.addCustomer + "/users/:id/customer", + verifyRequest, + validators.addCustomer, + controller.addCustomer ); // Add Business account to existing Customer account user.post( - "/users/:id/business", - validators.addBusiness, - controller.addBusiness + "/users/:id/business", + verifyRequest, + validators.addBusiness, + controller.addBusiness ); // Update existing Customer Account user.put( - "/users/:id/customer/profile", - validators.updateCustomerProfile, - controller.updateCustomerProfile + "/users/:id/customer/profile", + verifyRequest, + validators.updateCustomerProfile, + controller.updateCustomerProfile ); // Update existing Business Account user.put( - "/users/:id/business/profile", - validators.updateBusinessProfile, - controller.updateBusinessProfile + "/users/:id/business/profile", + verifyRequest, + validators.updateBusinessProfile, + controller.updateBusinessProfile ); export default user; diff --git a/api/src/router/user/validators.ts b/api/src/router/user/validators.ts index efe4afa1..2ea6f6af 100644 --- a/api/src/router/user/validators.ts +++ b/api/src/router/user/validators.ts @@ -1,5 +1,5 @@ import { body, param } from "express-validator"; -import { mwVaildator, verifyRequest } from "src/middlewares"; +import { mwVaildator } from "src/middlewares"; const idInParams = [param("id").notEmpty(), mwVaildator]; const notificationIdInParams = [ @@ -8,7 +8,6 @@ const notificationIdInParams = [ ]; export const createUser = [ - verifyRequest, body("consent").isBoolean(), body("email").isEmail(), body("type").isString(), // 'customer' | 'business' @@ -46,22 +45,19 @@ export const createUser = [ ]; export const notifications = [ - verifyRequest, ...idInParams, ...notificationIdInParams, ]; -export const getUser = [verifyRequest, ...idInParams]; +export const getUser = [...idInParams]; export const deposit = [ - verifyRequest, ...idInParams, body("amount").isString(), mwVaildator, ]; export const addCustomer = [ - verifyRequest, ...idInParams, body("customer.tag").isString(), body("customer.avatar").isString(), @@ -76,7 +72,6 @@ export const addCustomer = [ ]; export const updateCustomerProfile = [ - verifyRequest, ...idInParams, body("customer.tag").isString(), body("customer.avatar").isString(), @@ -84,7 +79,6 @@ export const updateCustomerProfile = [ ]; export const updateBusinessProfile = [ - verifyRequest, ...idInParams, body("business.story").isString(), body("business.tag").isString(), @@ -99,7 +93,6 @@ export const updateBusinessProfile = [ ]; export const addBusiness = [ - verifyRequest, ...idInParams, body("business.story").isString(), body("business.tag").isString(), @@ -125,14 +118,12 @@ export const addBusiness = [ ]; export const withdraw = [ - verifyRequest, ...idInParams, body("amount").isString(), mwVaildator, ]; export const transfer = [ - verifyRequest, ...idInParams, body("toUserId").isString(), body("amount").isString(), From 985030e7b0b04423e6fbaf112de8638e2ea910c7 Mon Sep 17 00:00:00 2001 From: Esraa Jbara Date: Mon, 10 Jan 2022 18:33:29 +0200 Subject: [PATCH 6/6] prettier --- api/src/router/user/index.ts | 93 ++++++++++++++++++++----------- api/src/router/user/validators.ts | 17 +----- 2 files changed, 62 insertions(+), 48 deletions(-) diff --git a/api/src/router/user/index.ts b/api/src/router/user/index.ts index 8a65710f..e245d553 100644 --- a/api/src/router/user/index.ts +++ b/api/src/router/user/index.ts @@ -1,5 +1,5 @@ import express from "express"; -import { verifyRequest } from "src/middlewares" +import { verifyRequest } from "src/middlewares"; import * as controller from "./controller"; import * as validators from "./validators"; @@ -7,78 +7,103 @@ const user = express(); // Get and create user(s) user.get("/users", controller.getAllUsers); -user.post("/users", verifyRequest, validators.createUser, controller.createUser); +user.post( + "/users", + verifyRequest, + validators.createUser, + controller.createUser +); user.get("/users/:id", validators.getUser, controller.getUser); // User dwolla info user.get("/users/email/:email", controller.getUserByEmail); // User database info // Get and create deposit(s) for a user user.get("/users/:id/deposit", validators.getUser, controller.getDeposits); -user.post("/users/:id/deposit", verifyRequest,validators.deposit, controller.deposit); +user.post( + "/users/:id/deposit", + verifyRequest, + validators.deposit, + controller.deposit +); // Get and create withdrawal(s) for a user user.get("/users/:id/withdraw", validators.getUser, controller.getWithdrawals); -user.post("/users/:id/withdraw", verifyRequest,validators.withdraw, controller.withdraw); +user.post( + "/users/:id/withdraw", + verifyRequest, + validators.withdraw, + controller.withdraw +); // Get and create transfer(s) for a user user.get("/users/:id/transfer", validators.getUser, controller.getTransfers); -user.post("/users/:id/transfer", verifyRequest, validators.transfer, controller.transferTo); +user.post( + "/users/:id/transfer", + verifyRequest, + validators.transfer, + controller.transferTo +); // Get Dwolla iav-token for a user (via POST) -user.post("/users/:id/iav-token", verifyRequest, validators.getUser, controller.getIAVToken); +user.post( + "/users/:id/iav-token", + verifyRequest, + validators.getUser, + controller.getIAVToken +); // Get funding sources for a user user.get( - "/users/:id/funding-sources", - verifyRequest, - validators.getUser, - controller.getFundingSources + "/users/:id/funding-sources", + verifyRequest, + validators.getUser, + controller.getFundingSources ); // Get and close notifications for a user user.get( - "/users/:id/notifications", - verifyRequest, - validators.getUser, - controller.getNotifications + "/users/:id/notifications", + verifyRequest, + validators.getUser, + controller.getNotifications ); user.delete( - "/users/:id/notifications/:notificationId", - verifyRequest, - validators.notifications, - controller.closeNotification + "/users/:id/notifications/:notificationId", + verifyRequest, + validators.notifications, + controller.closeNotification ); // Add Customer account to existing Business account user.post( - "/users/:id/customer", - verifyRequest, - validators.addCustomer, - controller.addCustomer + "/users/:id/customer", + verifyRequest, + validators.addCustomer, + controller.addCustomer ); // Add Business account to existing Customer account user.post( - "/users/:id/business", - verifyRequest, - validators.addBusiness, - controller.addBusiness + "/users/:id/business", + verifyRequest, + validators.addBusiness, + controller.addBusiness ); // Update existing Customer Account user.put( - "/users/:id/customer/profile", - verifyRequest, - validators.updateCustomerProfile, - controller.updateCustomerProfile + "/users/:id/customer/profile", + verifyRequest, + validators.updateCustomerProfile, + controller.updateCustomerProfile ); // Update existing Business Account user.put( - "/users/:id/business/profile", - verifyRequest, - validators.updateBusinessProfile, - controller.updateBusinessProfile + "/users/:id/business/profile", + verifyRequest, + validators.updateBusinessProfile, + controller.updateBusinessProfile ); export default user; diff --git a/api/src/router/user/validators.ts b/api/src/router/user/validators.ts index 2ea6f6af..fff5422a 100644 --- a/api/src/router/user/validators.ts +++ b/api/src/router/user/validators.ts @@ -44,18 +44,11 @@ export const createUser = [ mwVaildator, ]; -export const notifications = [ - ...idInParams, - ...notificationIdInParams, -]; +export const notifications = [...idInParams, ...notificationIdInParams]; export const getUser = [...idInParams]; -export const deposit = [ - ...idInParams, - body("amount").isString(), - mwVaildator, -]; +export const deposit = [...idInParams, body("amount").isString(), mwVaildator]; export const addCustomer = [ ...idInParams, @@ -117,11 +110,7 @@ export const addBusiness = [ mwVaildator, ]; -export const withdraw = [ - ...idInParams, - body("amount").isString(), - mwVaildator, -]; +export const withdraw = [...idInParams, body("amount").isString(), mwVaildator]; export const transfer = [ ...idInParams,