mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
remove all helpers on src/helpers (#8469)
Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
This commit is contained in:
parent
edce234745
commit
68edc47f65
@ -4,9 +4,9 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import { UserInputError } from 'apollo-server'
|
||||
import { hash } from 'bcryptjs'
|
||||
|
||||
import { getNeode } from '@db/neo4j'
|
||||
import encryptPassword from '@helpers/encryptPassword'
|
||||
|
||||
import existingEmailAddress from './helpers/existingEmailAddress'
|
||||
import generateNonce from './helpers/generateNonce'
|
||||
@ -46,7 +46,8 @@ export default {
|
||||
delete args.nonce
|
||||
delete args.email
|
||||
delete args.inviteCode
|
||||
args = encryptPassword(args)
|
||||
args.encryptedPassword = await hash(args.password, 10)
|
||||
delete args.password
|
||||
|
||||
const { driver } = context
|
||||
const session = driver.session()
|
||||
|
||||
@ -12,7 +12,6 @@ import { UserInputError } from 'apollo-server'
|
||||
import request from 'request'
|
||||
|
||||
import CONFIG from '@config/index'
|
||||
import asyncForEach from '@helpers/asyncForEach'
|
||||
|
||||
const fetch = (url) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -119,7 +118,7 @@ export const createOrUpdateLocations = async (nodeLabel, nodeId, locationName, s
|
||||
}
|
||||
|
||||
if (data.context) {
|
||||
await asyncForEach(data.context, async (ctx) => {
|
||||
for await (const ctx of data.context) {
|
||||
await createLocation(session, ctx)
|
||||
await session.writeTransaction((transaction) => {
|
||||
return transaction.run(
|
||||
@ -135,7 +134,7 @@ export const createOrUpdateLocations = async (nodeLabel, nodeId, locationName, s
|
||||
)
|
||||
})
|
||||
parent = ctx
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
locationId = data.id
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable promise/prefer-await-to-callbacks */
|
||||
/* eslint-disable security/detect-object-injection */
|
||||
/**
|
||||
* Provide a way to iterate for each element in an array while waiting for async functions to finish
|
||||
*
|
||||
* @param array
|
||||
* @param callback
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function asyncForEach(array, callback) {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
await callback(array[index], index, array)
|
||||
}
|
||||
}
|
||||
|
||||
export default asyncForEach
|
||||
@ -1,11 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
import { hashSync } from 'bcryptjs'
|
||||
|
||||
export default function (args) {
|
||||
// eslint-disable-next-line n/no-sync
|
||||
args.encryptedPassword = hashSync(args.password, 10)
|
||||
delete args.password
|
||||
return args
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
/* eslint-disable promise/avoid-new */
|
||||
// sometime we have to wait to check a db state by having a look into the db in a certain moment
|
||||
// or we wait a bit to check if we missed to set an await somewhere
|
||||
// see: https://www.sitepoint.com/delay-sleep-pause-wait/
|
||||
export function sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
// usage – 4 seconds for example
|
||||
// await sleep(4 * 1000)
|
||||
@ -1,36 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable promise/prefer-await-to-callbacks */
|
||||
/* eslint-disable security/detect-object-injection */
|
||||
/**
|
||||
* iterate through all fields and replace it with the callback result
|
||||
* @property data Array
|
||||
* @property fields Array
|
||||
* @property fieldName String
|
||||
* @property callback Function
|
||||
*/
|
||||
function walkRecursive(data, fields, fieldName, callback, _key?) {
|
||||
if (!Array.isArray(fields)) {
|
||||
throw new Error('please provide an fields array for the walkRecursive helper')
|
||||
}
|
||||
const fieldDef = fields.find((f) => f.field === _key)
|
||||
if (data && typeof data === 'string' && fieldDef) {
|
||||
if (!fieldDef.excludes?.includes(fieldName)) data = callback(data, _key)
|
||||
} else if (data && Array.isArray(data)) {
|
||||
// go into the rabbit hole and dig through that array
|
||||
data.forEach((res, index) => {
|
||||
data[index] = walkRecursive(data[index], fields, fieldName, callback, index)
|
||||
})
|
||||
} else if (data && typeof data === 'object') {
|
||||
// lets get some keys and stir them
|
||||
Object.keys(data).forEach((k) => {
|
||||
data[k] = walkRecursive(data[k], fields, fieldName, callback, k)
|
||||
})
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
export default walkRecursive
|
||||
@ -1,13 +1,42 @@
|
||||
/* eslint-disable security/detect-object-injection */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
/* eslint-disable promise/prefer-await-to-callbacks */
|
||||
/* eslint-disable @typescript-eslint/require-await */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
import walkRecursive from '@helpers/walkRecursive'
|
||||
|
||||
import { cleanHtml } from './helpers/cleanHtml'
|
||||
|
||||
// exclamation mark separetes field names, that should not be sanitized
|
||||
/**
|
||||
* iterate through all fields and replace it with the callback result
|
||||
* @property data Array
|
||||
* @property fields Array
|
||||
* @property fieldName String
|
||||
* @property callback Function
|
||||
*/
|
||||
const walkRecursive = (data, fields, fieldName, callback, _key?) => {
|
||||
if (!Array.isArray(fields)) {
|
||||
throw new Error('please provide an fields array for the walkRecursive helper')
|
||||
}
|
||||
const fieldDef = fields.find((f) => f.field === _key)
|
||||
if (data && typeof data === 'string' && fieldDef) {
|
||||
if (!fieldDef.excludes?.includes(fieldName)) data = callback(data, _key)
|
||||
} else if (data && Array.isArray(data)) {
|
||||
// go into the rabbit hole and dig through that array
|
||||
data.forEach((res, index) => {
|
||||
data[index] = walkRecursive(data[index], fields, fieldName, callback, index)
|
||||
})
|
||||
} else if (data && typeof data === 'object') {
|
||||
// lets get some keys and stir them
|
||||
Object.keys(data).forEach((k) => {
|
||||
data[k] = walkRecursive(data[k], fields, fieldName, callback, k)
|
||||
})
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// exclamation mark separates field names, that should not be sanitized
|
||||
const fields = [
|
||||
{ field: 'content', excludes: ['CreateMessage', 'Message'] },
|
||||
{ field: 'contentExcerpt' },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user