-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdev.js
More file actions
46 lines (44 loc) · 1.3 KB
/
dev.js
File metadata and controls
46 lines (44 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const hasher = require('@feathersjs/authentication-local/lib/utils/hash')
exports.seed = function (knex, Promise) {
// delete ALL existing entries
return Promise.all([
knex('agents').del(),
knex('credentials').del(),
knex('profiles').del()
])
.then(() => {
// insert person agent
const devPersonAgent = {}
return knex('agents').insert({ type: 'person' }).returning('id')
})
.then(([agentId]) => {
// insert person profile
const devPersonProfile = {
agentId,
name: 'Alice',
description: 'Hey, This is only a test.',
avatar: 'https://i.imgur.com/9p2dC14.gif' // source: https://imgur.com/gallery/OlVVE
}
return Promise.all([
Promise.resolve(agentId),
knex('profiles').insert(devPersonProfile)
])
})
.then(([agentId]) => {
// insert person credential
const devPersonCredential = {
agentId,
email: 'test@test.nz',
password: 'password'
}
return hashCredential(devPersonCredential)
}).then(credential => {
return knex('credentials').insert(credential)
})
}
function hashCredential (credential) {
return hasher(credential.password)
.then(hashedPassword => {
return Object.assign(credential, { password: hashedPassword })
})
}