mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Seed organizations
This commit is contained in:
parent
a981181e94
commit
1afcb4b0c9
@ -1,7 +1,5 @@
|
||||
export default {
|
||||
|
||||
|
||||
Organization: require('./organizations.js').default,
|
||||
Comment: require('./comments.js').default,
|
||||
|
||||
// Reports: require('./reports.js').default
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
export default () => {
|
||||
return `mutation {
|
||||
o1: CreateOrganization(
|
||||
id: "o1",
|
||||
name: "Democracy Deutschland",
|
||||
description: "Description for democracy-deutschland.",
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { name }
|
||||
o2: CreateOrganization(
|
||||
id: "o2",
|
||||
name: "Human-Connection",
|
||||
description: "Description for human-connection.",
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { name }
|
||||
o3: CreateOrganization(
|
||||
id: "o3",
|
||||
name: "Pro Veg",
|
||||
description: "Description for pro-veg.",
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { name }
|
||||
o4: CreateOrganization(
|
||||
id: "o4",
|
||||
name: "Greenpeace",
|
||||
description: "Description for greenpeace.",
|
||||
disabled: false,
|
||||
deleted: false
|
||||
) { name }
|
||||
|
||||
u1_c_o1: AddOrganizationCreatedBy(
|
||||
from: { id: "u1" },
|
||||
to: { id: "o1" }
|
||||
) { from { id } }
|
||||
u1_c_o2: AddOrganizationCreatedBy(
|
||||
from: { id: "u1" },
|
||||
to: { id: "o2" }
|
||||
) { from { id } }
|
||||
|
||||
u2_o_o1: AddOrganizationOwnedBy(
|
||||
from: { id: "u2" },
|
||||
to: { id: "o2" }
|
||||
) { from { id } }
|
||||
u2_c_o3: AddOrganizationOwnedBy(
|
||||
from: { id: "u2" },
|
||||
to: { id: "o3" }
|
||||
) { from { id } }
|
||||
}
|
||||
`
|
||||
}
|
||||
@ -20,6 +20,7 @@ const driver = neo4j().getDriver()
|
||||
const builders = {
|
||||
'badge': require('./badges.js').default,
|
||||
'user': require('./users.js').default,
|
||||
'organization': require('./organizations.js').default,
|
||||
'post': require('./posts.js').default,
|
||||
'category': require('./categories.js').default,
|
||||
'tag': require('./tags.js').default
|
||||
@ -27,6 +28,7 @@ const builders = {
|
||||
|
||||
const relationBuilders = {
|
||||
'user': require('./users.js').relate,
|
||||
'organization': require('./organizations.js').relate,
|
||||
'post': require('./posts.js').relate
|
||||
}
|
||||
|
||||
|
||||
35
src/seed/factories/organizations.js
Normal file
35
src/seed/factories/organizations.js
Normal file
@ -0,0 +1,35 @@
|
||||
import faker from 'faker'
|
||||
|
||||
export default function create (params) {
|
||||
const {
|
||||
id = `o${faker.random.number()}`,
|
||||
name = faker.comany.companyName(),
|
||||
description = faker.company.catchPhrase(),
|
||||
disabled = false,
|
||||
deleted = false
|
||||
} = params
|
||||
|
||||
return `
|
||||
mutation {
|
||||
${id}: CreateOrganization(
|
||||
id: "${id}",
|
||||
name: "${name}",
|
||||
description: "${description}",
|
||||
disabled: ${disabled},
|
||||
deleted: ${deleted}
|
||||
) { name }
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
export function relate(type, params) {
|
||||
const { from, to } = params
|
||||
return `
|
||||
mutation {
|
||||
${from}_${type}_${to}: AddOrganization${type}(
|
||||
from: { id: "${from}" },
|
||||
to: { id: "${to}" }
|
||||
) { from { id } }
|
||||
}
|
||||
`
|
||||
}
|
||||
@ -147,6 +147,21 @@ import seed from './data'
|
||||
relate('user', 'Shouted', { from: 'u4', to: 'p1' })
|
||||
])
|
||||
|
||||
await Promise.all([
|
||||
create('organization', { id: "o1", name: "Democracy Deutschland", description: "Description for democracy-deutschland."}),
|
||||
create('organization', { id: "o2", name: "Human-Connection", description: "Description for human-connection." }),
|
||||
create('organization', { id: "o3", name: "Pro Veg", description: "Description for pro-veg." }),
|
||||
create('organization', { id: "o4", name: "Greenpeace", description: "Description for greenpeace." })
|
||||
])
|
||||
|
||||
await Promise.all([
|
||||
relate('organization', 'CreatedBy', {from: 'u1', to: 'o1'}),
|
||||
relate('organization', 'CreatedBy', {from: 'u1', to: 'o2'}),
|
||||
relate('organization', 'OwnedBy', {from: 'u2', to: 'o2'}),
|
||||
relate('organization', 'OwnedBy', {from: 'u2', to: 'o3'})
|
||||
])
|
||||
|
||||
|
||||
} catch (err) {
|
||||
/* eslint-disable-next-line no-console */
|
||||
console.error(err)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user