Created
August 5, 2023 13:10
-
-
Save evaletolab/675b6407c8b290caac832ac5651a5637 to your computer and use it in GitHub Desktop.
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
// | |
// get list of accounting app build with TS (books,openexchangerates, bigcapital) | |
// https://github.com/topics/accounting?l=typescript | |
// https://www.npmjs.com/package/ratelimiter | |
export interface Transaction { | |
id?: string; | |
type?: 'payment' | 'loan' | 'memo'; | |
direction?: 'input' | 'output'; | |
memberId?: string; | |
memberFullName?: string; | |
date?: any; | |
dueDate?: any; | |
status?: 'closed' | 'unpaid' | 'paid'; | |
categories?: { [catgoryId: string]: boolean }; | |
lines?: TransactionLine[]; | |
total?: number; | |
dateMonth?: number; | |
dateYear?: number; | |
interest?: number; | |
interestType?: string; | |
} | |
export interface TransactionLine { | |
categoryId?: string; | |
categoryName?: string; | |
amount?: number; | |
description?: string; | |
} | |
export interface Template extends Transaction { | |
name?: string; | |
isTemplate: true; | |
} | |
export interface Aggregation { | |
id?: string; | |
input: { | |
total: number; | |
perCategory?: {}; | |
payment: { | |
total: number; | |
perCategory: object; | |
}; | |
loan: { | |
total: number; | |
perCategory: object; | |
perStatus: object; | |
}; | |
}; | |
output: { | |
total: number; | |
perCategory?: {}; | |
payment: { | |
total: number; | |
perCategory: object; | |
}; | |
loan: { | |
total: number; | |
perStatus: object; | |
perCategory: object; | |
}; | |
}; | |
transactionsCount: number; | |
} | |
export interface AggregationPerMonth extends Aggregation { | |
dateMonth: number; | |
dateYear: number; | |
} | |
export interface AggregationPerMonthPerMember extends AggregationPerMonth { | |
memberId: string; | |
} | |
import { Request, Response, NextFunction } from 'express'; | |
import { Container } from 'typedi'; | |
import jwt from 'jsonwebtoken'; | |
import config from '@/config'; | |
const authMiddleware = (req: Request, res: Response, next: NextFunction) => { | |
const Logger = Container.get('logger'); | |
const token = req.headers['x-access-token'] || req.query.token; | |
const onError = () => { | |
Logger.info('[auth_middleware] jwt verify error.'); | |
res.boom.unauthorized(); | |
}; | |
const onSuccess = (decoded) => { | |
req.token = decoded; | |
Logger.info('[auth_middleware] jwt verify success.'); | |
next(); | |
}; | |
if (!token) { return onError(); } | |
const verify = new Promise((resolve, reject) => { | |
jwt.verify(token, config.jwtSecret, async (error, decoded) => { | |
if (error) { | |
reject(error); | |
} else { | |
resolve(decoded); | |
} | |
}); | |
}); | |
verify.then(onSuccess).catch(onError); | |
}; | |
export default authMiddleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment