Skip to content

Commit 4f49ea3

Browse files
committed
feat: update seed user
1 parent 498b8cc commit 4f49ea3

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

server/src/database/seed.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { AuthService } from '@/services/auth.service'
1+
import { UserService } from '@/services/users.service'
2+
import * as bcrypt from 'bcrypt'
23
import Container from 'typedi'
34
import { db } from './db'
45
import { channelTypes } from './schema'
@@ -22,13 +23,16 @@ async function seedChannelTypes() {
2223

2324
async function seedDefaultAccount() {
2425
try {
25-
const authService = Container.get(AuthService)
26+
const userService = Container.get(UserService)
2627

27-
await authService.register({
28+
const hashedPassword = await bcrypt.hash('admin', 10)
29+
30+
await userService.create({
2831
2932
name: 'Admin',
30-
password: 'admin',
31-
passwordConfirm: 'admin',
33+
isVerified: true,
34+
password: hashedPassword,
35+
roles: ['ADMIN', 'USER'],
3236
})
3337

3438
console.log('Default account created')

server/src/services/users.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ export class UserService {
3939
}
4040

4141
public async create(fields: TNewUser) {
42-
const [user] = await db.insert(users).values(fields).returning()
42+
const [user] = await db
43+
.insert(users)
44+
.values({
45+
...fields,
46+
avatar: `https://ui-avatars.com/api/?background=random&name=${
47+
fields.name || fields.email || 'User'
48+
}`,
49+
})
50+
.returning()
4351

4452
await this.channelService.createDefaultChannel(user.id)
4553

0 commit comments

Comments
 (0)