mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 14:27:02 +08:00
refactor(server): use workspace model on user model (#9726)
This commit is contained in:
@@ -5,8 +5,9 @@ import ava, { TestFn } from 'ava';
|
||||
import Sinon from 'sinon';
|
||||
|
||||
import { EmailAlreadyUsed } from '../../base';
|
||||
import { Permission } from '../../core/permission';
|
||||
import { Permission } from '../../models/common';
|
||||
import { UserModel } from '../../models/user';
|
||||
import { WorkspaceMemberStatus } from '../../models/workspace';
|
||||
import { createTestingModule, initTestingDB } from '../utils';
|
||||
|
||||
interface Context {
|
||||
@@ -264,6 +265,7 @@ test('should trigger user.deleted event', async t => {
|
||||
},
|
||||
},
|
||||
type: Permission.Owner,
|
||||
status: WorkspaceMemberStatus.Accepted,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Prisma, type User, Workspace } from '@prisma/client';
|
||||
import { Prisma, type User } from '@prisma/client';
|
||||
import { pick } from 'lodash-es';
|
||||
|
||||
import {
|
||||
@@ -12,9 +12,9 @@ import {
|
||||
WrongSignInMethod,
|
||||
} from '../base';
|
||||
import type { Payload } from '../base/event/def';
|
||||
import { Permission } from '../core/permission';
|
||||
import { Quota_FreePlanV1_1 } from '../core/quota/schema';
|
||||
import { BaseModel } from './base';
|
||||
import type { Workspace } from './workspace';
|
||||
|
||||
const publicUserSelect = {
|
||||
id: true,
|
||||
@@ -219,18 +219,12 @@ export class UserModel extends BaseModel {
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
const ownedWorkspaces = await this.db.workspaceUserPermission.findMany({
|
||||
where: {
|
||||
userId: id,
|
||||
type: Permission.Owner,
|
||||
},
|
||||
});
|
||||
|
||||
const ownedWorkspaceIds = await this.models.workspace.findOwnedIds(id);
|
||||
const user = await this.db.user.delete({ where: { id } });
|
||||
|
||||
this.event.emit('user.deleted', {
|
||||
...user,
|
||||
ownedWorkspaces: ownedWorkspaces.map(w => w.workspaceId),
|
||||
ownedWorkspaces: ownedWorkspaceIds,
|
||||
});
|
||||
|
||||
return user;
|
||||
|
||||
Reference in New Issue
Block a user