mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
factory and seeding for invite codes
This commit is contained in:
parent
9449a55d42
commit
0c141b631f
@ -5,6 +5,7 @@ import { hashSync } from 'bcryptjs'
|
||||
import { Factory } from 'rosie'
|
||||
import { getDriver, getNeode } from './neo4j'
|
||||
import CONFIG from '../config/index.js'
|
||||
import generateInvieCode from '../schema/resolvers/helpers/generateInviteCode.js'
|
||||
|
||||
const neode = getNeode()
|
||||
|
||||
@ -216,6 +217,30 @@ Factory.define('unverifiedEmailAddress')
|
||||
return neode.create('UnverifiedEmailAddress', buildObject)
|
||||
})
|
||||
|
||||
const inviteCodeDefaults = {
|
||||
code: generateInvieCode(),
|
||||
createdAt: () => new Date().toISOString(),
|
||||
expiresAt: () => null,
|
||||
}
|
||||
|
||||
Factory.define('inviteCode')
|
||||
.attr(inviteCodeDefaults)
|
||||
.option('generatedById', null)
|
||||
.option('generatedBy', ['generatedById'], (generatedById) => {
|
||||
if (generatedById) return neode.find('User', generatedById)
|
||||
return Factory.build('user')
|
||||
})
|
||||
.after(async (buildObject, options) => {
|
||||
const [inviteCode, generatedBy] = await Promise.all([
|
||||
neode.create('InviteCode', buildObject),
|
||||
options.generatedBy,
|
||||
])
|
||||
await Promise.all([
|
||||
inviteCode.relateTo(generatedBy, 'generated'),
|
||||
])
|
||||
return inviteCode
|
||||
})
|
||||
|
||||
Factory.define('location')
|
||||
.attrs({
|
||||
name: 'Germany',
|
||||
|
||||
@ -541,6 +541,16 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
|
||||
),
|
||||
])
|
||||
|
||||
await Factory.build(
|
||||
'inviteCode',
|
||||
{
|
||||
code: 'AAAAAA',
|
||||
},
|
||||
{
|
||||
generatedBy: jennyRostock,
|
||||
},
|
||||
)
|
||||
|
||||
authenticatedUser = await louie.toJson()
|
||||
const mention1 =
|
||||
'Hey <a class="mention" data-mention-id="u3" href="/profile/u3">@jenny-rostock</a>, what\'s up?'
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
export default {
|
||||
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',
|
||||
},
|
||||
}
|
||||
@ -1,18 +1,16 @@
|
||||
export default {
|
||||
code: { type: 'string', primary: true },
|
||||
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
|
||||
uses: { type: 'int', default: () => 0 },
|
||||
maxUses: { type: 'int', default: () => 1 },
|
||||
active: { type: 'boolean', default: () => true },
|
||||
createdBy: {
|
||||
expiresAt: { type: 'string', isoDate: true, default: null },
|
||||
generated: {
|
||||
type: 'relationship',
|
||||
relationship: 'CREATED',
|
||||
relationship: 'GENERATED',
|
||||
target: 'User',
|
||||
direction: 'in',
|
||||
},
|
||||
usedBy: {
|
||||
redeemed: {
|
||||
type: 'relationship',
|
||||
relationship: 'USED',
|
||||
relationship: 'REDEEMED',
|
||||
target: 'User',
|
||||
direction: 'in',
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user