mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 02:26:21 +08:00
feat(server): init user module (#2018)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { UsersModule } from './users';
|
||||
import { WorkspaceModule } from './workspaces';
|
||||
|
||||
export const BusinessModules = [WorkspaceModule];
|
||||
export const BusinessModules = [WorkspaceModule, UsersModule];
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { UserResolver } from './resolver';
|
||||
|
||||
@Module({
|
||||
providers: [UserResolver],
|
||||
})
|
||||
export class UsersModule {}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Args, Field, ID, ObjectType, Query, Resolver } from '@nestjs/graphql';
|
||||
import type { users } from '@prisma/client';
|
||||
|
||||
import { PrismaService } from '../../prisma/service';
|
||||
|
||||
@ObjectType()
|
||||
export class User implements users {
|
||||
@Field(() => ID)
|
||||
id!: string;
|
||||
@Field({ description: 'User name' })
|
||||
name!: string;
|
||||
@Field({ description: 'User email' })
|
||||
email!: string;
|
||||
@Field({ description: 'User password', nullable: true })
|
||||
password!: string;
|
||||
@Field({ description: 'User avatar url', nullable: true })
|
||||
avatar_url!: string;
|
||||
@Field({ description: 'User token nonce', nullable: true })
|
||||
token_nonce!: number;
|
||||
@Field({ description: 'User created date', nullable: true })
|
||||
created_at!: Date;
|
||||
}
|
||||
|
||||
@Resolver(() => User)
|
||||
export class UserResolver {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
@Query(() => User, {
|
||||
name: 'user',
|
||||
description: 'Get user by email',
|
||||
})
|
||||
async user(@Args('email') email: string) {
|
||||
return this.prisma.users.findUnique({
|
||||
where: { email },
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
import {
|
||||
Args,
|
||||
Field,
|
||||
ID,
|
||||
Mutation,
|
||||
ObjectType,
|
||||
Query,
|
||||
registerEnumType,
|
||||
@@ -17,11 +21,20 @@ export enum WorkspaceType {
|
||||
|
||||
registerEnumType(WorkspaceType, {
|
||||
name: 'WorkspaceType',
|
||||
description: 'Workspace type',
|
||||
valuesMap: {
|
||||
Normal: {
|
||||
description: 'Normal workspace',
|
||||
},
|
||||
Private: {
|
||||
description: 'Private workspace',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@ObjectType()
|
||||
export class Workspace implements workspaces {
|
||||
@Field()
|
||||
@Field(() => ID)
|
||||
id!: string;
|
||||
@Field({ description: 'is Public workspace' })
|
||||
public!: boolean;
|
||||
@@ -53,4 +66,20 @@ export class WorkspaceResolver {
|
||||
where: { id },
|
||||
});
|
||||
}
|
||||
|
||||
// create workspace
|
||||
@Mutation(() => Workspace, {
|
||||
name: 'createWorkspace',
|
||||
description: 'Create workspace',
|
||||
})
|
||||
async createWorkspace() {
|
||||
return this.prisma.workspaces.create({
|
||||
data: {
|
||||
id: randomUUID(),
|
||||
type: WorkspaceType.Private,
|
||||
public: false,
|
||||
created_at: new Date(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user