mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-12 23:35:58 +00:00
Fix lint
This commit is contained in:
parent
0a9991b979
commit
e1bb6ed74e
@ -35,8 +35,8 @@ export default class ActivityPub {
|
||||
|
||||
handleFollowActivity(activity) {
|
||||
debug(`inside FOLLOW ${activity.actor}`)
|
||||
let toActorName = extractNameFromId(activity.object)
|
||||
let fromDomain = extractDomainFromUrl(activity.actor)
|
||||
const toActorName = extractNameFromId(activity.object)
|
||||
const fromDomain = extractDomainFromUrl(activity.actor)
|
||||
const dataSource = this.dataSource
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -53,7 +53,7 @@ export default class ActivityPub {
|
||||
toActorObject = JSON.parse(toActorObject)
|
||||
await this.dataSource.addSharedInboxEndpoint(toActorObject.endpoints.sharedInbox)
|
||||
|
||||
let followersCollectionPage = await this.dataSource.getFollowersCollectionPage(
|
||||
const followersCollectionPage = await this.dataSource.getFollowersCollectionPage(
|
||||
activity.object,
|
||||
)
|
||||
|
||||
@ -222,6 +222,7 @@ export default class ActivityPub {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async trySend(activity, fromName, host, url, tries = 5) {
|
||||
try {
|
||||
return await signAndSend(activity, fromName, host, url)
|
||||
|
||||
@ -2,6 +2,7 @@ export default class Collections {
|
||||
constructor(dataSource) {
|
||||
this.dataSource = dataSource
|
||||
}
|
||||
|
||||
getFollowersCollection(actorId) {
|
||||
return this.dataSource.getFollowersCollection(actorId)
|
||||
}
|
||||
|
||||
@ -303,6 +303,7 @@ export default class NitroDataSource {
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
async saveFollowingCollectionPage(followingCollection, onlyNewestItem = true) {
|
||||
debug('inside saveFollowers')
|
||||
let orderedItems = followingCollection.orderedItems
|
||||
@ -470,6 +471,7 @@ export default class NitroDataSource {
|
||||
throwErrorIfApolloErrorOccurred(result)
|
||||
return result.data.SharedInboxEnpoint
|
||||
}
|
||||
|
||||
async addSharedInboxEndpoint(uri) {
|
||||
try {
|
||||
const result = await this.client.mutate({
|
||||
|
||||
@ -97,7 +97,7 @@ export function verifySignature(url, headers) {
|
||||
// private: signing
|
||||
function constructSigningString(url, headers) {
|
||||
const urlObj = new URL(url)
|
||||
let signingString = `(request-target): post ${urlObj.pathname}${
|
||||
const signingString = `(request-target): post ${urlObj.pathname}${
|
||||
urlObj.search !== '' ? urlObj.search : ''
|
||||
}`
|
||||
return Object.keys(headers).reduce((result, key) => {
|
||||
|
||||
@ -40,70 +40,72 @@ export function signAndSend(activity, fromName, targetDomain, url) {
|
||||
// fix for development: replace with http
|
||||
url = url.indexOf('localhost') > -1 ? url.replace('https', 'http') : url
|
||||
debug(`passhprase = ${CONFIG.PRIVATE_KEY_PASSPHRASE}`)
|
||||
return new Promise(async (resolve, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
debug('inside signAndSend')
|
||||
// get the private key
|
||||
const result = await activityPub.dataSource.client.query({
|
||||
query: gql`
|
||||
activityPub.dataSource.client
|
||||
.query({
|
||||
query: gql`
|
||||
query {
|
||||
User(slug: "${fromName}") {
|
||||
privateKey
|
||||
}
|
||||
}
|
||||
`,
|
||||
})
|
||||
})
|
||||
.then(result => {
|
||||
if (result.error) {
|
||||
reject(result.error)
|
||||
} else {
|
||||
// add security context
|
||||
const parsedActivity = JSON.parse(activity)
|
||||
if (Array.isArray(parsedActivity['@context'])) {
|
||||
parsedActivity['@context'].push('https://w3id.org/security/v1')
|
||||
} else {
|
||||
const context = [parsedActivity['@context']]
|
||||
context.push('https://w3id.org/security/v1')
|
||||
parsedActivity['@context'] = context
|
||||
}
|
||||
|
||||
if (result.error) {
|
||||
reject(result.error)
|
||||
} else {
|
||||
// add security context
|
||||
const parsedActivity = JSON.parse(activity)
|
||||
if (Array.isArray(parsedActivity['@context'])) {
|
||||
parsedActivity['@context'].push('https://w3id.org/security/v1')
|
||||
} else {
|
||||
const context = [parsedActivity['@context']]
|
||||
context.push('https://w3id.org/security/v1')
|
||||
parsedActivity['@context'] = context
|
||||
}
|
||||
// deduplicate context strings
|
||||
parsedActivity['@context'] = [...new Set(parsedActivity['@context'])]
|
||||
const privateKey = result.data.User[0].privateKey
|
||||
const date = new Date().toUTCString()
|
||||
|
||||
// deduplicate context strings
|
||||
parsedActivity['@context'] = [...new Set(parsedActivity['@context'])]
|
||||
const privateKey = result.data.User[0].privateKey
|
||||
const date = new Date().toUTCString()
|
||||
|
||||
debug(`url = ${url}`)
|
||||
request(
|
||||
{
|
||||
url: url,
|
||||
headers: {
|
||||
Host: targetDomain,
|
||||
Date: date,
|
||||
Signature: createSignature({
|
||||
privateKey,
|
||||
keyId: `${activityPub.endpoint}/activitypub/users/${fromName}#main-key`,
|
||||
url,
|
||||
debug(`url = ${url}`)
|
||||
request(
|
||||
{
|
||||
url: url,
|
||||
headers: {
|
||||
Host: targetDomain,
|
||||
Date: date,
|
||||
Signature: createSignature({
|
||||
privateKey,
|
||||
keyId: `${activityPub.endpoint}/activitypub/users/${fromName}#main-key`,
|
||||
url,
|
||||
headers: {
|
||||
Host: targetDomain,
|
||||
Date: date,
|
||||
'Content-Type': 'application/activity+json',
|
||||
},
|
||||
}),
|
||||
'Content-Type': 'application/activity+json',
|
||||
},
|
||||
}),
|
||||
'Content-Type': 'application/activity+json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify(parsedActivity),
|
||||
},
|
||||
(error, response) => {
|
||||
if (error) {
|
||||
debug(`Error = ${JSON.stringify(error, null, 2)}`)
|
||||
reject(error)
|
||||
} else {
|
||||
debug('Response Headers:', JSON.stringify(response.headers, null, 2))
|
||||
debug('Response Body:', JSON.stringify(response.body, null, 2))
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
method: 'POST',
|
||||
body: JSON.stringify(parsedActivity),
|
||||
},
|
||||
(error, response) => {
|
||||
if (error) {
|
||||
debug(`Error = ${JSON.stringify(error, null, 2)}`)
|
||||
reject(error)
|
||||
} else {
|
||||
debug('Response Headers:', JSON.stringify(response.headers, null, 2))
|
||||
debug('Response Body:', JSON.stringify(response.body, null, 2))
|
||||
resolve()
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -97,8 +97,6 @@ const invitationLimitReached = rule({
|
||||
return record.get('limitReached')
|
||||
})
|
||||
return limitReached
|
||||
} catch (e) {
|
||||
throw e
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import slugify from 'slug'
|
||||
export default async function uniqueSlug(string, isUnique) {
|
||||
let slug = slugify(string || 'anonymous', {
|
||||
const slug = slugify(string || 'anonymous', {
|
||||
lower: true,
|
||||
})
|
||||
if (await isUnique(slug)) return slug
|
||||
|
||||
@ -8,8 +8,8 @@ import linkifyHtml from 'linkifyjs/html'
|
||||
const embedToAnchor = content => {
|
||||
const $ = cheerio.load(content)
|
||||
$('div[data-url-embed]').each((i, el) => {
|
||||
let url = el.attribs['data-url-embed']
|
||||
let aTag = $(`<a href="${url}" target="_blank" data-url-embed="">${url}</a>`)
|
||||
const url = el.attribs['data-url-embed']
|
||||
const aTag = $(`<a href="${url}" target="_blank" data-url-embed="">${url}</a>`)
|
||||
$(el).replaceWith(aTag)
|
||||
})
|
||||
return $('body').html()
|
||||
@ -87,7 +87,7 @@ function clean(dirty) {
|
||||
b: 'strong',
|
||||
s: 'strike',
|
||||
img: function(tagName, attribs) {
|
||||
let src = attribs.src
|
||||
const src = attribs.src
|
||||
|
||||
if (!src) {
|
||||
// remove broken images
|
||||
|
||||
@ -18,7 +18,7 @@ export default {
|
||||
false,
|
||||
)
|
||||
|
||||
let transactionRes = await session.run(
|
||||
const transactionRes = await session.run(
|
||||
`
|
||||
MATCH (post:Post {id: $postId}), (comment:Comment {id: $commentId}), (author:User {id: $userId})
|
||||
MERGE (post)<-[:COMMENTS]-(comment)<-[:WROTE]-(author)
|
||||
|
||||
@ -5,7 +5,6 @@ import { host, login, gql } from '../../jest/helpers'
|
||||
const factory = Factory()
|
||||
let client
|
||||
let createCommentVariables
|
||||
let createPostVariables
|
||||
let createCommentVariablesSansPostId
|
||||
let createCommentVariablesWithNonExistentPost
|
||||
let userParams
|
||||
@ -26,7 +25,7 @@ const createCommentMutation = gql`
|
||||
}
|
||||
}
|
||||
`
|
||||
createPostVariables = {
|
||||
const createPostVariables = {
|
||||
id: 'p1',
|
||||
title: 'post to comment on',
|
||||
content: 'please comment on me',
|
||||
@ -325,7 +324,7 @@ describe('ManageComments', () => {
|
||||
}
|
||||
`
|
||||
|
||||
let deleteCommentVariables = {
|
||||
const deleteCommentVariables = {
|
||||
id: 'c456',
|
||||
}
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ export default {
|
||||
const { id, type } = params
|
||||
|
||||
const session = context.driver.session()
|
||||
let transactionRes = await session.run(
|
||||
const transactionRes = await session.run(
|
||||
`MATCH (node {id: $id}), (user:User {id: $userId})
|
||||
WHERE $type IN labels(node) AND NOT $id = $userId
|
||||
MERGE (user)-[relation:FOLLOWS]->(node)
|
||||
@ -29,7 +29,7 @@ export default {
|
||||
const { id, type } = params
|
||||
const session = context.driver.session()
|
||||
|
||||
let transactionRes = await session.run(
|
||||
const transactionRes = await session.run(
|
||||
`MATCH (user:User {id: $userId})-[relation:FOLLOWS]->(node {id: $id})
|
||||
WHERE $type IN labels(node)
|
||||
DELETE relation
|
||||
|
||||
@ -41,8 +41,7 @@ describe('follow', () => {
|
||||
describe('follow user', () => {
|
||||
describe('unauthenticated follow', () => {
|
||||
it('throws authorization error', async () => {
|
||||
let client
|
||||
client = new GraphQLClient(host)
|
||||
const client = new GraphQLClient(host)
|
||||
await expect(client.request(mutationFollowUser('u2'))).rejects.toThrow('Not Authorised')
|
||||
})
|
||||
})
|
||||
@ -93,8 +92,7 @@ describe('follow', () => {
|
||||
// follow
|
||||
await clientUser1.request(mutationFollowUser('u2'))
|
||||
// unfollow
|
||||
let client
|
||||
client = new GraphQLClient(host)
|
||||
const client = new GraphQLClient(host)
|
||||
await expect(client.request(mutationUnfollowUser('u2'))).rejects.toThrow('Not Authorised')
|
||||
})
|
||||
})
|
||||
|
||||
@ -4,7 +4,7 @@ import { host, login } from '../../jest/helpers'
|
||||
|
||||
const factory = Factory()
|
||||
let client
|
||||
let userParams = {
|
||||
const userParams = {
|
||||
id: 'you',
|
||||
email: 'test@example.org',
|
||||
password: '1234',
|
||||
@ -34,7 +34,7 @@ describe('Notification', () => {
|
||||
})
|
||||
|
||||
describe('currentUser { notifications }', () => {
|
||||
let variables = {}
|
||||
const variables = {}
|
||||
|
||||
describe('authenticated', () => {
|
||||
let headers
|
||||
@ -79,7 +79,7 @@ describe('currentUser { notifications }', () => {
|
||||
}
|
||||
}
|
||||
}`
|
||||
let variables = { read: false }
|
||||
const variables = { read: false }
|
||||
it('returns only unread notifications of current user', async () => {
|
||||
const expected = {
|
||||
currentUser: {
|
||||
|
||||
@ -41,7 +41,7 @@ export default {
|
||||
SET u.encryptedPassword = $encryptedNewPassword
|
||||
RETURN pr
|
||||
`
|
||||
let transactionRes = await session.run(cypher, {
|
||||
const transactionRes = await session.run(cypher, {
|
||||
stillValid,
|
||||
email,
|
||||
code,
|
||||
|
||||
@ -10,7 +10,7 @@ const driver = getDriver()
|
||||
|
||||
const getAllPasswordResets = async () => {
|
||||
const session = driver.session()
|
||||
let transactionRes = await session.run('MATCH (r:PasswordReset) RETURN r')
|
||||
const transactionRes = await session.run('MATCH (r:PasswordReset) RETURN r')
|
||||
const resets = transactionRes.records.map(record => record.get('r'))
|
||||
session.close()
|
||||
return resets
|
||||
@ -84,9 +84,9 @@ describe('passwordReset', () => {
|
||||
}
|
||||
|
||||
const mutation = `mutation($code: String!, $email: String!, $newPassword: String!) { resetPassword(code: $code, email: $email, newPassword: $newPassword) }`
|
||||
let email = 'user@example.org'
|
||||
let code = 'abcdef'
|
||||
let newPassword = 'supersecret'
|
||||
const email = 'user@example.org'
|
||||
const code = 'abcdef'
|
||||
const newPassword = 'supersecret'
|
||||
let variables
|
||||
|
||||
describe('invalid email', () => {
|
||||
|
||||
@ -337,7 +337,7 @@ describe('DeletePost', () => {
|
||||
}
|
||||
`
|
||||
|
||||
let variables = {
|
||||
const variables = {
|
||||
id: 'p1',
|
||||
}
|
||||
|
||||
|
||||
@ -300,7 +300,7 @@ describe('SignupVerification', () => {
|
||||
}
|
||||
`
|
||||
describe('given valid password and email', () => {
|
||||
let variables = {
|
||||
const variables = {
|
||||
nonce: '123456',
|
||||
name: 'John Doe',
|
||||
password: '123',
|
||||
|
||||
@ -60,7 +60,7 @@ export default {
|
||||
if (!dbResponse) return null
|
||||
const { report, submitter, resource, type } = dbResponse
|
||||
|
||||
let response = {
|
||||
const response = {
|
||||
...report.properties,
|
||||
post: null,
|
||||
comment: null,
|
||||
|
||||
@ -4,7 +4,7 @@ import { UserInputError } from 'apollo-server'
|
||||
const instance = neode()
|
||||
|
||||
const getUserAndBadge = async ({ badgeKey, userId }) => {
|
||||
let user = await instance.first('User', 'id', userId)
|
||||
const user = await instance.first('User', 'id', userId)
|
||||
const badge = await instance.first('Badge', 'id', badgeKey)
|
||||
if (!user) throw new UserInputError("Couldn't find a user with that id")
|
||||
if (!badge) throw new UserInputError("Couldn't find a badge with that id")
|
||||
@ -36,8 +36,6 @@ export default {
|
||||
userId,
|
||||
},
|
||||
)
|
||||
} catch (err) {
|
||||
throw err
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ export default {
|
||||
const { id, type } = params
|
||||
|
||||
const session = context.driver.session()
|
||||
let transactionRes = await session.run(
|
||||
const transactionRes = await session.run(
|
||||
`MATCH (node {id: $id})<-[:WROTE]-(userWritten:User), (user:User {id: $userId})
|
||||
WHERE $type IN labels(node) AND NOT userWritten.id = $userId
|
||||
MERGE (user)-[relation:SHOUTED]->(node)
|
||||
@ -29,7 +29,7 @@ export default {
|
||||
const { id, type } = params
|
||||
const session = context.driver.session()
|
||||
|
||||
let transactionRes = await session.run(
|
||||
const transactionRes = await session.run(
|
||||
`MATCH (user:User {id: $userId})-[relation:SHOUTED]->(node {id: $id})
|
||||
WHERE $type IN labels(node)
|
||||
DELETE relation
|
||||
|
||||
@ -60,8 +60,7 @@ describe('shout', () => {
|
||||
describe('shout foreign post', () => {
|
||||
describe('unauthenticated shout', () => {
|
||||
it('throws authorization error', async () => {
|
||||
let client
|
||||
client = new GraphQLClient(host)
|
||||
const client = new GraphQLClient(host)
|
||||
await expect(client.request(mutationShoutPost('p1'))).rejects.toThrow('Not Authorised')
|
||||
})
|
||||
})
|
||||
@ -109,8 +108,7 @@ describe('shout', () => {
|
||||
// shout
|
||||
await clientUser1.request(mutationShoutPost('p2'))
|
||||
// unshout
|
||||
let client
|
||||
client = new GraphQLClient(host)
|
||||
const client = new GraphQLClient(host)
|
||||
await expect(client.request(mutationUnshoutPost('p2'))).rejects.toThrow('Not Authorised')
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
export const query = (cypher, session) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let data = []
|
||||
const data = []
|
||||
session.run(cypher).subscribe({
|
||||
onNext: function(record) {
|
||||
let item = {}
|
||||
const item = {}
|
||||
record.keys.forEach(key => {
|
||||
item[key] = record.get(key)
|
||||
})
|
||||
@ -34,7 +34,7 @@ const queryOne = (cypher, session) => {
|
||||
export default {
|
||||
Query: {
|
||||
statistics: async (parent, args, { driver, user }) => {
|
||||
return new Promise(async resolve => {
|
||||
return new Promise(resolve => {
|
||||
const session = driver.session()
|
||||
const queries = {
|
||||
countUsers:
|
||||
@ -54,18 +54,24 @@ export default {
|
||||
countFollows: 'MATCH (:User)-[r:FOLLOWS]->(:User) RETURN COUNT(r) AS countFollows',
|
||||
countShouts: 'MATCH (:User)-[r:SHOUTED]->(:Post) RETURN COUNT(r) AS countShouts',
|
||||
}
|
||||
let data = {
|
||||
countUsers: (await queryOne(queries.countUsers, session)).countUsers.low,
|
||||
countPosts: (await queryOne(queries.countPosts, session)).countPosts.low,
|
||||
countComments: (await queryOne(queries.countComments, session)).countComments.low,
|
||||
countNotifications: (await queryOne(queries.countNotifications, session))
|
||||
.countNotifications.low,
|
||||
countOrganizations: (await queryOne(queries.countOrganizations, session))
|
||||
.countOrganizations.low,
|
||||
countProjects: (await queryOne(queries.countProjects, session)).countProjects.low,
|
||||
countInvites: (await queryOne(queries.countInvites, session)).countInvites.low,
|
||||
countFollows: (await queryOne(queries.countFollows, session)).countFollows.low,
|
||||
countShouts: (await queryOne(queries.countShouts, session)).countShouts.low,
|
||||
const data = {
|
||||
countUsers: queryOne(queries.countUsers, session).then(res => res.countUsers.low),
|
||||
countPosts: queryOne(queries.countPosts, session).then(res => res.countPosts.low),
|
||||
countComments: queryOne(queries.countComments, session).then(
|
||||
res => res.countComments.low,
|
||||
),
|
||||
countNotifications: queryOne(queries.countNotifications, session).then(
|
||||
res => res.countNotifications.low,
|
||||
),
|
||||
countOrganizations: queryOne(queries.countOrganizations, session).then(
|
||||
res => res.countOrganizations.low,
|
||||
),
|
||||
countProjects: queryOne(queries.countProjects, session).then(
|
||||
res => res.countProjects.low,
|
||||
),
|
||||
countInvites: queryOne(queries.countInvites, session).then(res => res.countInvites.low),
|
||||
countFollows: queryOne(queries.countFollows, session).then(res => res.countFollows.low),
|
||||
countShouts: queryOne(queries.countShouts, session).then(res => res.countShouts.low),
|
||||
}
|
||||
resolve(data)
|
||||
})
|
||||
|
||||
@ -49,7 +49,7 @@ export default {
|
||||
}
|
||||
},
|
||||
changePassword: async (_, { oldPassword, newPassword }, { driver, user }) => {
|
||||
let currentUser = await instance.find('User', user.id)
|
||||
const currentUser = await instance.find('User', user.id)
|
||||
|
||||
const encryptedPassword = currentUser.get('encryptedPassword')
|
||||
if (!(await bcrypt.compareSync(oldPassword, encryptedPassword))) {
|
||||
|
||||
@ -296,7 +296,7 @@ describe('change password', () => {
|
||||
|
||||
describe('correct password', () => {
|
||||
it('changes the password if given correct credentials "', async () => {
|
||||
let response = await client.request(
|
||||
const response = await client.request(
|
||||
mutation({
|
||||
oldPassword: '1234',
|
||||
newPassword: '12345',
|
||||
|
||||
@ -23,7 +23,7 @@ export default {
|
||||
UpdateUser: async (object, args, context, resolveInfo) => {
|
||||
args = await fileUpload(args, { file: 'avatarUpload', url: 'avatar' })
|
||||
try {
|
||||
let user = await instance.find('User', args.id)
|
||||
const user = await instance.find('User', args.id)
|
||||
if (!user) return null
|
||||
await user.update(args)
|
||||
return user.toJson()
|
||||
@ -60,7 +60,7 @@ export default {
|
||||
const { id } = parent
|
||||
const statement = `MATCH(u:User {id: {id}})-[:PRIMARY_EMAIL]->(e:EmailAddress) RETURN e`
|
||||
const result = await instance.cypher(statement, { id })
|
||||
let [{ email }] = result.records.map(r => r.get('e').properties)
|
||||
const [{ email }] = result.records.map(r => r.get('e').properties)
|
||||
return email
|
||||
},
|
||||
...Resolver('User', {
|
||||
|
||||
@ -21,7 +21,7 @@ const findGqlFiles = dir => {
|
||||
return results
|
||||
}
|
||||
|
||||
let typeDefs = []
|
||||
const typeDefs = []
|
||||
|
||||
findGqlFiles(__dirname).forEach(file => {
|
||||
typeDefs.push(fs.readFileSync(file).toString('utf-8'))
|
||||
|
||||
@ -40,15 +40,13 @@ export const cleanDatabase = async (options = {}) => {
|
||||
const cypher = 'MATCH (n) DETACH DELETE n'
|
||||
try {
|
||||
return await session.run(cypher)
|
||||
} catch (error) {
|
||||
throw error
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
}
|
||||
|
||||
export default function Factory(options = {}) {
|
||||
let {
|
||||
const {
|
||||
seedServerHost = 'http://127.0.0.1:4001',
|
||||
neo4jDriver = getDriver(),
|
||||
neodeInstance = neode(),
|
||||
|
||||
@ -37,17 +37,17 @@ const difficulties = ['easy', 'medium', 'hard']
|
||||
|
||||
export default {
|
||||
randomItem: (items, filter) => {
|
||||
let ids = filter
|
||||
const ids = filter
|
||||
? Object.keys(items).filter(id => {
|
||||
return filter(items[id])
|
||||
})
|
||||
: _.keys(items)
|
||||
let randomIds = _.shuffle(ids)
|
||||
const randomIds = _.shuffle(ids)
|
||||
return items[randomIds.pop()]
|
||||
},
|
||||
randomItems: (items, key = 'id', min = 1, max = 1) => {
|
||||
let randomIds = _.shuffle(_.keys(items))
|
||||
let res = []
|
||||
const randomIds = _.shuffle(_.keys(items))
|
||||
const res = []
|
||||
|
||||
const count = _.random(min, max)
|
||||
|
||||
@ -86,8 +86,8 @@ export default {
|
||||
if (allowEmpty === false && count === 0) {
|
||||
count = 1
|
||||
}
|
||||
let categorieIds = _.shuffle(_.keys(seederstore.categories))
|
||||
let ids = []
|
||||
const categorieIds = _.shuffle(_.keys(seederstore.categories))
|
||||
const ids = []
|
||||
for (let i = 0; i < count; i++) {
|
||||
ids.push(categorieIds.pop())
|
||||
}
|
||||
@ -95,7 +95,7 @@ export default {
|
||||
},
|
||||
randomAddresses: () => {
|
||||
const count = Math.round(Math.random() * 3)
|
||||
let addresses = []
|
||||
const addresses = []
|
||||
for (let i = 0; i < count; i++) {
|
||||
addresses.push({
|
||||
city: faker.address.city(),
|
||||
@ -116,7 +116,7 @@ export default {
|
||||
* @param key the field key that is represented in the values (slug, name, etc.)
|
||||
*/
|
||||
mapIdsByKey: (items, values, key) => {
|
||||
let res = []
|
||||
const res = []
|
||||
values.forEach(value => {
|
||||
res.push(_.find(items, [key, value]).id.toString())
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user