feat: add register-guest api

This commit is contained in:
wancat committed 2024-06-17 19:23:30 +08:00
1 parent b5c601f4a9
commit 1d725d82ae
4 files changed
+63 -3

No files matched your search

+17
View File
@@ -1,4 +1,5 @@
import { Express } from 'express'
import { format } from 'date-fns'
import { User, UserProfile } from '@linux-odyssey/models'
import { hashPassword } from '../utils/auth.js'
@@ -31,6 +32,22 @@ export async function createUser(
return user
}
export async function createGuestUser() {
const username = `guest_${format(new Date(), 'yyyyMMddHHmmss')}`
const user = new User({
username,
email: `${username}@example.com`,
})
await user.save()
const profile = new UserProfile({
user,
})
await profile.save()
return user
}
export function leaderboard() {
return UserProfile.aggregate([
{