Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #132 from capsule-corp-ternoa/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Leouarz authored Dec 6, 2021
2 parents 89f60ce + 3f3010f commit 88b4de7
Show file tree
Hide file tree
Showing 26 changed files with 1,385 additions and 1,146 deletions.
431 changes: 259 additions & 172 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nft-marketplace-back",
"version": "1.1.0",
"name": "nft-marketplace-api",
"version": "1.2.0",
"description": "ternoa nft marketplace server",
"main": "dist/index.js",
"scripts": {
Expand All @@ -17,25 +17,26 @@
"author": "",
"license": "ISC",
"dependencies": {
"@sentry/node": "^6.13.3",
"@sentry/tracing": "^6.13.3",
"@sentry/node": "^6.14.1",
"@sentry/tracing": "^6.14.1",
"abort-controller": "^3.0.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"crypto-js": "^4.1.1",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"graphql": "^15.7.0",
"graphql": "^16.0.1",
"graphql-request": "^3.6.1",
"install": "^0.13.0",
"joi": "^17.4.2",
"mongoose": "^6.0.12",
"mongoose-paginate-v2": "^1.4.2",
"node-cache": "^5.1.2",
"node-fetch": "^2.6.2",
"npm": "^8.1.1",
"node-fetch": "^2.6.6",
"npm": "^8.1.3",
"oauth": "^0.9.15",
"pino": "^7.0.5",
"socket.io": "^4.3.1"
"pino": "^7.1.0",
"socket.io": "^4.3.2"
},
"devDependencies": {
"@types/compression": "^1.7.2",
Expand All @@ -44,7 +45,7 @@
"@types/express": "^4.17.13",
"@types/mongoose-paginate-v2": "^1.4.0",
"@types/node": "^16.11.6",
"@types/node-fetch": "^2.5.10",
"@types/node-fetch": "^2.5.12",
"@types/oauth": "^0.9.1",
"@types/pino": "^6.3.12",
"nodemon": "^2.0.14",
Expand Down
23 changes: 21 additions & 2 deletions src/api/controllers/categories/controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import CategoryService from "../../services/category";
import { NextFunction, Request, Response } from "express";
import { validationGetCategories, validationCreateCategory } from "../../validators/categoryValidators";

export class Controller {
async getCategories(
_: Request,
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
res.json(await CategoryService.getCategories().catch(next));
try{
const queryValues = validationGetCategories(req.query)
res.json(await CategoryService.getCategories(queryValues));
}catch(err){
next(err)
}
}

async addCategory(
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
try{
const queryValues = validationCreateCategory(req.body)
res.json(await CategoryService.addCategory(queryValues));
}catch(err){
next(err)
}
}
}
export default new Controller();
5 changes: 4 additions & 1 deletion src/api/controllers/categories/router.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import express from "express";
import controller from "./controller";
export default express.Router().get("/", controller.getCategories);
export default express
.Router()
.get("/", controller.getCategories)
// .post("/", controller.addCategory)
80 changes: 33 additions & 47 deletions src/api/controllers/follows/controller.ts
Original file line number Diff line number Diff line change
@@ -1,117 +1,103 @@
import FollowService from "../../services/follow";
import { NextFunction, Request, Response } from "express";
import { LIMIT_MAX_PAGINATION, decryptCookie } from "../../../utils";
import { decryptCookie } from "../../../utils";
import { validationCountFollowersFollowing, validationFollowUnfollow, validationGetFollowersFollowing, validationIsUserFollowing } from "../../validators/followValidators";

export class Controller {
async follow(
async getUserFollowers(
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
try{
const {walletIdFollowed, walletIdFollower} = req.query
const {cookie} = JSON.parse(req.body)
if (!walletIdFollowed || !walletIdFollower) next(new Error("wallet ids parameters are needed"));
if(cookie && decryptCookie(cookie) === walletIdFollower){
res.json(await FollowService.follow(walletIdFollowed as string, walletIdFollower as string));
}else{
throw new Error('Unvalid authentication')
}
const queryValues = validationGetFollowersFollowing({ ...req.params, ...req.query })
res.json(await FollowService.getUserFollowers(queryValues));
}catch(err){
next(err);
}
}

async unfollow(
async getUserFollowings(
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
try{
const {walletIdFollowed, walletIdFollower} = req.query
const {cookie} = JSON.parse(req.body)
if (!walletIdFollowed || !walletIdFollower) next(new Error("wallet ids parameters are needed"));
if(cookie && decryptCookie(cookie) === walletIdFollower){
res.json(await FollowService.unfollow(walletIdFollowed as string, walletIdFollower as string));
}else{
throw new Error('Unvalid authentication')
}
const queryValues = validationGetFollowersFollowing({ ...req.params, ...req.query })
res.json(await FollowService.getUserFollowings(queryValues));
}catch(err){
next(err);
}
}

async isUserFollowing(
async countUserFollowers(
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
try{
const {walletIdFollowed, walletIdFollower} = req.query
if (!walletIdFollowed || !walletIdFollower) next(new Error("wallet ids parameters are needed"));
res.json(await FollowService.isUserFollowing(walletIdFollower as string, walletIdFollowed as string));
const queryValues = validationCountFollowersFollowing(req.params)
res.json(await FollowService.countUserFollowers(queryValues))
}catch(err){
next(err);
}
}

async getUserFollowers(
async countUserFollowing(
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
try{
if (!req.params.walletId) next(new Error("wallet id parameter is needed"));
const {page, limit, certifiedOnly, nameOrAddressSearch} = req.query
if (page && (isNaN(Number(page)) || Number(page) < 1)) throw new Error("Page argument is invalid")
if (limit && (isNaN(Number(limit)) || Number(limit) < 1 || Number(limit) > LIMIT_MAX_PAGINATION)) throw new Error("Limit argument is invalid")
const users = await FollowService.getUserFollowers(req.params.walletId, page ? page as string : "1", limit ? limit as string : String(LIMIT_MAX_PAGINATION), certifiedOnly as string, nameOrAddressSearch as string)
res.json(users);
const queryValues = validationCountFollowersFollowing(req.params)
res.json(await FollowService.countUserFollowing(queryValues))
}catch(err){
next(err);
}
}
async getUserFollowings(

async isUserFollowing(
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
try{
if (!req.params.walletId) next(new Error("wallet id parameter is needed"));
const {page, limit, certifiedOnly, nameOrAddressSearch} = req.query
if (page && (isNaN(Number(page)) || Number(page) < 1)) throw new Error("Page argument is invalid")
if (limit && (isNaN(Number(limit)) || Number(limit) < 1 || Number(limit) > LIMIT_MAX_PAGINATION)) throw new Error("Limit argument is invalid")
const users = await FollowService.getUserFollowings(req.params.walletId, page ? page as string : "1", limit ? limit as string : String(LIMIT_MAX_PAGINATION), certifiedOnly as string, nameOrAddressSearch as string)
res.json(users);
const queryValues = validationIsUserFollowing(req.query)
res.json(await FollowService.isUserFollowing(queryValues));
}catch(err){
next(err);
}
}

async countUserFollowers(
async follow(
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
try{
if (!req.params.walletId) next(new Error("wallet id parameter is needed"));
const count = await FollowService.countUserFollowers(req.params.walletId)
res.json(count);
const queryValues = validationFollowUnfollow({...req.query, ...JSON.parse(req.body)})
if(decryptCookie(queryValues.cookie) === queryValues.walletIdFollower){
res.json(await FollowService.follow(queryValues));
}else{
throw new Error('Unvalid authentication')
}
}catch(err){
next(err);
}
}

async countUserFollowing(
async unfollow(
req: Request,
res: Response,
next: NextFunction
): Promise<void> {
try{
if (!req.params.walletId) next(new Error("wallet id parameter is needed"));
const count = await FollowService.countUserFollowing(req.params.walletId)
res.json(count);
const queryValues = validationFollowUnfollow({...req.query, ...JSON.parse(req.body)})
if(decryptCookie(queryValues.cookie) === queryValues.walletIdFollower){
res.json(await FollowService.unfollow(queryValues));
}else{
throw new Error('Unvalid authentication')
}
}catch(err){
next(err);
}
Expand Down
Loading

0 comments on commit 88b4de7

Please sign in to comment.