diff --git a/backend/src/bootstrap/neode.js b/backend/src/bootstrap/neode.js index 419cb1032..12ac3c299 100644 --- a/backend/src/bootstrap/neode.js +++ b/backend/src/bootstrap/neode.js @@ -1,88 +1,8 @@ import Neode from 'neode' -import uuid from 'uuid/v4' export default function setupNeode(options) { const { uri, username, password } = options const neodeInstance = new Neode(uri, username, password) - neodeInstance.model('InvitationCode', { - createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, - token: { type: 'string', primary: true, token: true }, - generatedBy: { - type: 'relationship', - relationship: 'GENERATED', - target: 'User', - direction: 'in', - }, - activated: { - type: 'relationship', - relationship: 'ACTIVATED', - target: 'EmailAddress', - direction: 'out', - }, - }) - neodeInstance.model('EmailAddress', { - email: { type: 'string', primary: true, lowercase: true, email: true }, - createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, - verifiedAt: { type: 'string', isoDate: true }, - nonce: { type: 'string', token: true }, - belongsTo: { - type: 'relationship', - relationship: 'BELONGS_TO', - target: 'User', - direction: 'out', - }, - }) - neodeInstance.model('User', { - id: { type: 'string', primary: true, default: uuid }, // TODO: should be type: 'uuid' but simplified for our tests - actorId: { type: 'string', allow: [null] }, - name: { type: 'string', min: 3 }, - email: { type: 'string', lowercase: true, email: true }, - slug: 'string', - encryptedPassword: 'string', - avatar: { type: 'string', allow: [null] }, - coverImg: { type: 'string', allow: [null] }, - deleted: { type: 'boolean', default: false }, - disabled: { type: 'boolean', default: false }, - role: 'string', - publicKey: 'string', - privateKey: 'string', - wasInvited: 'boolean', - wasSeeded: 'boolean', - locationName: { type: 'string', allow: [null] }, - about: { type: 'string', allow: [null] }, - primaryEmail: { - type: 'relationship', - relationship: 'PRIMARY_EMAIL', - target: 'EmailAddress', - direction: 'out', - }, - following: { - type: 'relationship', - relationship: 'FOLLOWS', - target: 'User', - direction: 'out', - }, - followedBy: { - type: 'relationship', - relationship: 'FOLLOWS', - target: 'User', - direction: 'in', - }, - friends: { type: 'relationship', relationship: 'FRIENDS', target: 'User', direction: 'both' }, - disabledBy: { - type: 'relationship', - relationship: 'DISABLED', - target: 'User', - direction: 'in', - }, - invitedBy: { type: 'relationship', relationship: 'INVITED', target: 'User', direction: 'in' }, - createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, - updatedAt: { - type: 'string', - isoDate: true, - required: true, - default: () => new Date().toISOString(), - }, - }) + neodeInstance.withDirectory(`${__dirname}/../models`) return neodeInstance } diff --git a/backend/src/models/EmailAddress.js b/backend/src/models/EmailAddress.js new file mode 100644 index 000000000..ddd56c297 --- /dev/null +++ b/backend/src/models/EmailAddress.js @@ -0,0 +1,12 @@ +module.exports = { + email: { type: 'string', primary: true, lowercase: true, email: true }, + createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, + verifiedAt: { type: 'string', isoDate: true }, + nonce: { type: 'string', token: true }, + belongsTo: { + type: 'relationship', + relationship: 'BELONGS_TO', + target: 'User', + direction: 'out', + }, +} diff --git a/backend/src/models/InvitationCode.js b/backend/src/models/InvitationCode.js new file mode 100644 index 000000000..f137f6c15 --- /dev/null +++ b/backend/src/models/InvitationCode.js @@ -0,0 +1,16 @@ +module.exports = { + createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, + token: { type: 'string', primary: true, token: true }, + generatedBy: { + type: 'relationship', + relationship: 'GENERATED', + target: 'User', + direction: 'in', + }, + activated: { + type: 'relationship', + relationship: 'ACTIVATED', + target: 'EmailAddress', + direction: 'out', + }, +} diff --git a/backend/src/models/User.js b/backend/src/models/User.js new file mode 100644 index 000000000..9ad07cf11 --- /dev/null +++ b/backend/src/models/User.js @@ -0,0 +1,54 @@ +import uuid from 'uuid/v4' + +module.exports = { + id: { type: 'string', primary: true, default: uuid }, // TODO: should be type: 'uuid' but simplified for our tests + actorId: { type: 'string', allow: [null] }, + name: { type: 'string', min: 3 }, + email: { type: 'string', lowercase: true, email: true }, + slug: 'string', + encryptedPassword: 'string', + avatar: { type: 'string', allow: [null] }, + coverImg: { type: 'string', allow: [null] }, + deleted: { type: 'boolean', default: false }, + disabled: { type: 'boolean', default: false }, + role: 'string', + publicKey: 'string', + privateKey: 'string', + wasInvited: 'boolean', + wasSeeded: 'boolean', + locationName: { type: 'string', allow: [null] }, + about: { type: 'string', allow: [null] }, + primaryEmail: { + type: 'relationship', + relationship: 'PRIMARY_EMAIL', + target: 'EmailAddress', + direction: 'out', + }, + following: { + type: 'relationship', + relationship: 'FOLLOWS', + target: 'User', + direction: 'out', + }, + followedBy: { + type: 'relationship', + relationship: 'FOLLOWS', + target: 'User', + direction: 'in', + }, + friends: { type: 'relationship', relationship: 'FRIENDS', target: 'User', direction: 'both' }, + disabledBy: { + type: 'relationship', + relationship: 'DISABLED', + target: 'User', + direction: 'in', + }, + invitedBy: { type: 'relationship', relationship: 'INVITED', target: 'User', direction: 'in' }, + createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() }, + updatedAt: { + type: 'string', + isoDate: true, + required: true, + default: () => new Date().toISOString(), + }, +}