mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Categories posts in seeding
This commit is contained in:
parent
9dba02cf09
commit
437e8589f8
@ -1,22 +0,0 @@
|
|||||||
export default function (data) {
|
|
||||||
return `
|
|
||||||
mutation {
|
|
||||||
cat1: CreateCategory( id: "cat1", name: "Just For Fun", slug: "justforfun", icon: "smile" ) { name }
|
|
||||||
cat2: CreateCategory( id: "cat2", name: "Happyness & Values", slug: "happyness-values", icon: "heart-o" ) { name }
|
|
||||||
cat3: CreateCategory( id: "cat3", name: "Health & Wellbeing", slug: "health-wellbeing", icon: "medkit" ) { name }
|
|
||||||
cat4: CreateCategory( id: "cat4", name: "Environment & Nature", slug: "environment-nature", icon: "tree" ) { name }
|
|
||||||
cat5: CreateCategory( id: "cat5", name: "Animal Protection", slug: "animalprotection", icon: "paw" ) { name }
|
|
||||||
cat6: CreateCategory( id: "cat6", name: "Humanrights Justice", slug: "humanrights-justice", icon: "balance-scale" ) { name }
|
|
||||||
cat7: CreateCategory( id: "cat7", name: "Education & Sciences", slug: "education-sciences", icon: "graduation-cap" ) { name }
|
|
||||||
cat8: CreateCategory( id: "cat8", name: "Cooperation & Development", slug: "cooperation-development", icon: "users" ) { name }
|
|
||||||
cat9: CreateCategory( id: "cat9", name: "Democracy & Politics", slug: "democracy-politics", icon: "university" ) { name }
|
|
||||||
cat10: CreateCategory( id: "cat10", name: "Economy & Finances", slug: "economy-finances", icon: "money" ) { name }
|
|
||||||
cat11: CreateCategory( id: "cat11", name: "Energy & Technology", slug: "energy-technology", icon: "flash" ) { name }
|
|
||||||
cat12: CreateCategory( id: "cat12", name: "IT, Internet & Data Privacy", slug: "it-internet-dataprivacy", icon: "mouse-pointer" ) { name }
|
|
||||||
cat13: CreateCategory( id: "cat13", name: "Art, Curlure & Sport", slug: "art-culture-sport", icon: "paint-brush" ) { name }
|
|
||||||
cat14: CreateCategory( id: "cat14", name: "Freedom of Speech", slug: "freedomofspeech", icon: "bullhorn" ) { name }
|
|
||||||
cat15: CreateCategory( id: "cat15", name: "Consumption & Sustainability", slug: "consumption-sustainability", icon: "shopping-cart" ) { name }
|
|
||||||
cat16: CreateCategory( id: "cat16", name: "Global Peace & Nonviolence", slug: "globalpeace-nonviolence", icon: "angellist" ) { name }
|
|
||||||
}
|
|
||||||
`
|
|
||||||
}
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
Badge: require('./badges.js').default,
|
Badge: require('./badges.js').default,
|
||||||
Category: require('./categories.js').default,
|
|
||||||
Tags: require('./tags.js').default,
|
Tags: require('./tags.js').default,
|
||||||
|
|
||||||
UserBadges: require('./users-badges.js').default,
|
UserBadges: require('./users-badges.js').default,
|
||||||
|
|||||||
21
src/seed/factories/categories.js
Normal file
21
src/seed/factories/categories.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import faker from 'faker'
|
||||||
|
|
||||||
|
export default function (params) {
|
||||||
|
const {
|
||||||
|
id = `cat${faker.random.number()}`,
|
||||||
|
name,
|
||||||
|
slug,
|
||||||
|
icon
|
||||||
|
} = params
|
||||||
|
|
||||||
|
return `
|
||||||
|
mutation {
|
||||||
|
CreateCategory(
|
||||||
|
id: "${id}",
|
||||||
|
name: "${name}",
|
||||||
|
slug: "${slug}",
|
||||||
|
icon: "${icon}"
|
||||||
|
) { id, name }
|
||||||
|
}
|
||||||
|
`
|
||||||
|
}
|
||||||
@ -20,7 +20,8 @@ const driver = neo4j().getDriver()
|
|||||||
|
|
||||||
const builders = {
|
const builders = {
|
||||||
'user': require('./users.js').default,
|
'user': require('./users.js').default,
|
||||||
'post': require('./posts.js').default
|
'post': require('./posts.js').default,
|
||||||
|
'category': require('./categories.js').default
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildMutation = (model, parameters) => {
|
const buildMutation = (model, parameters) => {
|
||||||
|
|||||||
@ -15,12 +15,21 @@ export default function (params) {
|
|||||||
image = faker.image.image(),
|
image = faker.image.image(),
|
||||||
visibility = 'public',
|
visibility = 'public',
|
||||||
disabled = false,
|
disabled = false,
|
||||||
deleted = false
|
deleted = false,
|
||||||
|
tagIds = [],
|
||||||
|
categoryIds = []
|
||||||
} = params
|
} = params
|
||||||
|
|
||||||
|
const categoryRelations = categoryIds.map((categoryId) => {
|
||||||
|
return `${id}_${categoryId}: AddPostCategories(
|
||||||
|
from: {id: "${id}"},
|
||||||
|
to: {id: "${categoryId}"}
|
||||||
|
) { from { id } }`
|
||||||
|
})
|
||||||
|
|
||||||
return `
|
return `
|
||||||
mutation {
|
mutation {
|
||||||
CreatePost(
|
${id}: CreatePost(
|
||||||
id: "${id}",
|
id: "${id}",
|
||||||
title: "${title}",
|
title: "${title}",
|
||||||
content: "${content}",
|
content: "${content}",
|
||||||
@ -29,6 +38,7 @@ export default function (params) {
|
|||||||
disabled: ${disabled},
|
disabled: ${disabled},
|
||||||
deleted: ${deleted}
|
deleted: ${deleted}
|
||||||
) { id, title }
|
) { id, title }
|
||||||
|
${categoryRelations.join('\n')}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,12 +27,33 @@ import seed from './data'
|
|||||||
email: 'user@example.org',
|
email: 'user@example.org',
|
||||||
password: '1234'
|
password: '1234'
|
||||||
}, host)
|
}, host)
|
||||||
await create('post', {id: 'p1'}, { headers: asAdmin } )
|
|
||||||
await create('post', {id: 'p2'}, { headers: asModerator } )
|
const categories = await Promise.all([
|
||||||
await create('post', {id: 'p3'}, { headers: asUser } )
|
create('category', { id: "cat1", name: "Just For Fun", slug: "justforfun", icon: "smile" }),
|
||||||
await create('post', {id: 'p4'}, { headers: asAdmin } )
|
create('category', { id: "cat2", name: "Happyness & Values", slug: "happyness-values", icon: "heart-o" }),
|
||||||
await create('post', {id: 'p5'}, { headers: asModerator } )
|
create('category', { id: "cat3", name: "Health & Wellbeing", slug: "health-wellbeing", icon: "medkit" }),
|
||||||
await create('post', {id: 'p6'}, { headers: asUser } )
|
create('category', { id: "cat4", name: "Environment & Nature", slug: "environment-nature", icon: "tree" }),
|
||||||
|
create('category', { id: "cat5", name: "Animal Protection", slug: "animalprotection", icon: "paw" }),
|
||||||
|
create('category', { id: "cat6", name: "Humanrights Justice", slug: "humanrights-justice", icon: "balance-scale" }),
|
||||||
|
create('category', { id: "cat7", name: "Education & Sciences", slug: "education-sciences", icon: "graduation-cap" }),
|
||||||
|
create('category', { id: "cat8", name: "Cooperation & Development", slug: "cooperation-development", icon: "users" }),
|
||||||
|
create('category', { id: "cat9", name: "Democracy & Politics", slug: "democracy-politics", icon: "university" }),
|
||||||
|
create('category', { id: "cat10", name: "Economy & Finances", slug: "economy-finances", icon: "money" }),
|
||||||
|
create('category', { id: "cat11", name: "Energy & Technology", slug: "energy-technology", icon: "flash" }),
|
||||||
|
create('category', { id: "cat12", name: "IT, Internet & Data Privacy", slug: "it-internet-dataprivacy", icon: "mouse-pointer" }),
|
||||||
|
create('category', { id: "cat13", name: "Art, Curlure & Sport", slug: "art-culture-sport", icon: "paint-brush" }),
|
||||||
|
create('category', { id: "cat14", name: "Freedom of Speech", slug: "freedomofspeech", icon: "bullhorn" }),
|
||||||
|
create('category', { id: "cat15", name: "Consumption & Sustainability", slug: "consumption-sustainability", icon: "shopping-cart" }),
|
||||||
|
create('category', { id: "cat16", name: "Global Peace & Nonviolence", slug: "globalpeace-nonviolence", icon: "angellist" })
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
await create('post', {id: 'p1', categoryIds: ['cat1']}, { headers: asAdmin } )
|
||||||
|
await create('post', {id: 'p2', categoryIds: ['cat2']}, { headers: asModerator } )
|
||||||
|
await create('post', {id: 'p3', categoryIds: ['cat3']}, { headers: asUser } )
|
||||||
|
await create('post', {id: 'p4', categoryIds: ['cat4']}, { headers: asAdmin } )
|
||||||
|
await create('post', {id: 'p5', categoryIds: ['cat5']}, { headers: asModerator } )
|
||||||
|
await create('post', {id: 'p6', categoryIds: ['cat6']}, { headers: asUser } )
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
/* eslint-disable-next-line no-console */
|
/* eslint-disable-next-line no-console */
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user