Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 64x 64x 64x 64x 64x 64x 64x 1x 27x 27x 1x 1x 56x 56x 56x 133x 56x 5x 1x 3x 3x 1x 3x 1x 91x 1x 1x 1x 1x 1x 1x | import { Request, Response } from '@loopback/rest'; import moment from 'moment'; import { authenticator } from 'otplib'; import { v4 as uuidv4 } from 'uuid'; import voucherCode from 'voucher-code-generator'; import { roles } from '../../config'; import { logger } from '../../services/logger.services'; import { getErrorObj } from '../../utils/errorHandler'; import errorMessages from '../../utils/errorMessages'; authenticator.options = { digits: 6 }; export const promoCode = () => { let coupenList = voucherCode.generate({ length: 12, prefix: "saw-", pattern: "#####" }) return coupenList[0] } export const genOTP = () => { return authenticator.generate(process.env.OTP_TOKEN_SECRET!) } export const getUID = uuidv4 export const failureHandler = async (res: Response, code: number, error: any, className?: string) => { let actualError = error let methodName = error.methodName // error = error.message || error // code = error.code || code className = error.className || className let { statusCode = 422, errorString = errorMessages.somethingWentWrong } = await getErrorObj(error, code) const logData = { status: "Failed", code: statusCode, endPoint: res.req.url, methodName, className, message: errorString, actualError, payload: getPayloadDetails(res.req), }; logger.error(logData); return res.status(logData.code).send(logData.message); } //NOTE: response might be string,array,object,schema so it declared any export const successHandler = (res: Response, code?: number, result?: any) => { const logData = { endPoint: res.req.url, status: "Success", code: code ?? 200, result: result ?? [], payload: getPayloadDetails(res.req) }; // logger.info(logData); return res.status(logData.code).send(logData.result); } export const getFilesAndFields = (request: Request) => { const uploadedFiles = request.files; let files: object[] = []; if (Array.isArray(uploadedFiles)) { files = uploadedFiles//.map(mapper); } else { for (const filename in uploadedFiles) { files.push(...uploadedFiles[filename])//.map(mapper)); } } return { files, fields: request.body }; } export const validatePayload = (payload: any, expectedReq: { properties: any }) => { let methodName = "validatePayload" let payloadKeys = Object.keys(payload) let expectedKeys = Object.keys(expectedReq.properties) let unKnownKey = payloadKeys.every((key: string) => expectedKeys.includes(key)) if (!unKnownKey && expectedKeys.length) { // console.log("Expected: ",expectedKeys.sort()) // console.log("Actual Payload: ",payloadKeys.sort()) throw { code: 422, message: errorMessages.unexpectedPayloadInput, methodName } } } export const HandleDomainName = (domainName: string) => { Eif (domainName) { return domainName.includes(".") ? domainName : domainName + ".com" } return domainName } export const isAdmin = (currentUser: { role?: { roleType?: string } }) => { return currentUser?.role?.roleType === roles.admin } export const getPayloadDetails = (request: Request) => { return { params: request.params, body: request.body, query: request.query } } export const isValidDate = (date: Date | any) => { try { return moment(date, moment.ISO_8601).isValid() } catch (error) { return false } } export const ValidateIPaddress = (ipAddress: string) => { Eif (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipAddress)) { return true } return false } |