mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
refactor(server): rename settings to user-settings (#11161)
This commit is contained in:
@@ -89,7 +89,7 @@ test('should create invitation notification and email', async t => {
|
||||
test('should not send invitation email if user setting is not to receive invitation email', async t => {
|
||||
const { notificationService } = t.context;
|
||||
const inviteId = randomUUID();
|
||||
await t.context.models.settings.set(member.id, {
|
||||
await t.context.models.userSettings.set(member.id, {
|
||||
receiveInvitationEmail: false,
|
||||
});
|
||||
const invitationMailCount = t.context.module.mails.count('MemberInvitation');
|
||||
@@ -150,7 +150,7 @@ test('should not send invitation accepted email if user settings is not receive
|
||||
const { notificationService } = t.context;
|
||||
const inviteId = randomUUID();
|
||||
// should not send email if user settings is not receive invitation email
|
||||
await t.context.models.settings.set(owner.id, {
|
||||
await t.context.models.userSettings.set(owner.id, {
|
||||
receiveInvitationEmail: false,
|
||||
});
|
||||
const invitationAcceptedMailCount =
|
||||
@@ -560,7 +560,7 @@ test('should send mention email by user setting', async t => {
|
||||
|
||||
// update user setting to not receive mention email
|
||||
const mentionMailCount = t.context.module.mails.count('Mention');
|
||||
await t.context.models.settings.set(member.id, {
|
||||
await t.context.models.userSettings.set(member.id, {
|
||||
receiveMentionEmail: false,
|
||||
});
|
||||
await notificationService.createMention({
|
||||
|
||||
@@ -45,7 +45,7 @@ export class NotificationService {
|
||||
}
|
||||
|
||||
private async sendMentionEmail(input: MentionNotificationCreate) {
|
||||
const userSetting = await this.models.settings.get(input.userId);
|
||||
const userSetting = await this.models.userSettings.get(input.userId);
|
||||
if (!userSetting.receiveMentionEmail) {
|
||||
return;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ export class NotificationService {
|
||||
// make it easier to test in dev mode
|
||||
this.logger.debug(`Invite link: ${inviteUrl}`);
|
||||
}
|
||||
const userSetting = await this.models.settings.get(input.userId);
|
||||
const userSetting = await this.models.userSettings.get(input.userId);
|
||||
if (!userSetting.receiveInvitationEmail) {
|
||||
return;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ export class NotificationService {
|
||||
const inviterUserId = input.userId;
|
||||
const inviteeUserId = input.body.createdByUserId;
|
||||
const workspaceId = input.body.workspaceId;
|
||||
const userSetting = await this.models.settings.get(inviterUserId);
|
||||
const userSetting = await this.models.userSettings.get(inviterUserId);
|
||||
if (!userSetting.receiveInvitationEmail) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ import test from 'ava';
|
||||
|
||||
import {
|
||||
createTestingApp,
|
||||
getSettings,
|
||||
getUserSettings,
|
||||
TestingApp,
|
||||
updateSettings,
|
||||
updateUserSettings,
|
||||
} from '../../../__tests__/utils';
|
||||
|
||||
let app: TestingApp;
|
||||
@@ -19,7 +19,7 @@ test.after.always(async () => {
|
||||
|
||||
test('should get user settings', async t => {
|
||||
await app.signup();
|
||||
const settings = await getSettings(app);
|
||||
const settings = await getUserSettings(app);
|
||||
t.deepEqual(settings, {
|
||||
receiveInvitationEmail: true,
|
||||
receiveMentionEmail: true,
|
||||
@@ -28,30 +28,30 @@ test('should get user settings', async t => {
|
||||
|
||||
test('should update user settings', async t => {
|
||||
await app.signup();
|
||||
await updateSettings(app, {
|
||||
await updateUserSettings(app, {
|
||||
receiveInvitationEmail: false,
|
||||
receiveMentionEmail: false,
|
||||
});
|
||||
const settings = await getSettings(app);
|
||||
const settings = await getUserSettings(app);
|
||||
t.deepEqual(settings, {
|
||||
receiveInvitationEmail: false,
|
||||
receiveMentionEmail: false,
|
||||
});
|
||||
|
||||
await updateSettings(app, {
|
||||
await updateUserSettings(app, {
|
||||
receiveMentionEmail: true,
|
||||
});
|
||||
const settings2 = await getSettings(app);
|
||||
const settings2 = await getUserSettings(app);
|
||||
t.deepEqual(settings2, {
|
||||
receiveInvitationEmail: false,
|
||||
receiveMentionEmail: true,
|
||||
});
|
||||
|
||||
await updateSettings(app, {
|
||||
await updateUserSettings(app, {
|
||||
// ignore undefined value
|
||||
receiveInvitationEmail: undefined,
|
||||
});
|
||||
const settings3 = await getSettings(app);
|
||||
const settings3 = await getUserSettings(app);
|
||||
t.deepEqual(settings3, {
|
||||
receiveInvitationEmail: false,
|
||||
receiveMentionEmail: true,
|
||||
@@ -61,7 +61,7 @@ test('should update user settings', async t => {
|
||||
test('should throw error when update user settings with invalid input', async t => {
|
||||
await app.signup();
|
||||
await t.throwsAsync(
|
||||
updateSettings(app, {
|
||||
updateUserSettings(app, {
|
||||
receiveInvitationEmail: false,
|
||||
// @ts-expect-error invalid value
|
||||
receiveMentionEmail: null,
|
||||
@@ -75,7 +75,7 @@ test('should throw error when update user settings with invalid input', async t
|
||||
test('should not update user settings when not logged in', async t => {
|
||||
await app.logout();
|
||||
await t.throwsAsync(
|
||||
updateSettings(app, {
|
||||
updateUserSettings(app, {
|
||||
receiveInvitationEmail: false,
|
||||
receiveMentionEmail: false,
|
||||
}),
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
Throttle,
|
||||
UserNotFound,
|
||||
} from '../../base';
|
||||
import { Models, SettingsSchema } from '../../models';
|
||||
import { Models, UserSettingsSchema } from '../../models';
|
||||
import { Public } from '../auth/guard';
|
||||
import { sessionUser } from '../auth/service';
|
||||
import { CurrentUser } from '../auth/session';
|
||||
@@ -32,10 +32,10 @@ import {
|
||||
ManageUserInput,
|
||||
PublicUserType,
|
||||
RemoveAvatar,
|
||||
SettingsType,
|
||||
UpdateSettingsInput,
|
||||
UpdateUserInput,
|
||||
UpdateUserSettingsInput,
|
||||
UserOrLimitedUser,
|
||||
UserSettingsType,
|
||||
UserType,
|
||||
} from './types';
|
||||
|
||||
@@ -168,20 +168,20 @@ export class UserSettingsResolver {
|
||||
})
|
||||
async updateSettings(
|
||||
@CurrentUser() user: CurrentUser,
|
||||
@Args('input', { type: () => UpdateSettingsInput })
|
||||
input: UpdateSettingsInput
|
||||
@Args('input', { type: () => UpdateUserSettingsInput })
|
||||
input: UpdateUserSettingsInput
|
||||
) {
|
||||
SettingsSchema.parse(input);
|
||||
await this.models.settings.set(user.id, input);
|
||||
UserSettingsSchema.parse(input);
|
||||
await this.models.userSettings.set(user.id, input);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ResolveField(() => SettingsType, {
|
||||
@ResolveField(() => UserSettingsType, {
|
||||
name: 'settings',
|
||||
description: 'Get user settings',
|
||||
})
|
||||
async getSettings(@CurrentUser() me: CurrentUser): Promise<SettingsType> {
|
||||
return await this.models.settings.get(me.id);
|
||||
async getSettings(@CurrentUser() me: CurrentUser): Promise<UserSettingsType> {
|
||||
return await this.models.userSettings.get(me.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import type { User } from '@prisma/client';
|
||||
|
||||
import {
|
||||
PublicUser,
|
||||
Settings,
|
||||
SettingsInput,
|
||||
UserSettings,
|
||||
UserSettingsInput,
|
||||
WorkspaceUser,
|
||||
} from '../../models';
|
||||
import { type CurrentUser } from '../auth/session';
|
||||
@@ -115,7 +115,7 @@ export class RemoveAvatar {
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class SettingsType implements Settings {
|
||||
export class UserSettingsType implements UserSettings {
|
||||
@Field({ description: 'Receive invitation email' })
|
||||
receiveInvitationEmail!: boolean;
|
||||
|
||||
@@ -139,7 +139,7 @@ export class ManageUserInput {
|
||||
}
|
||||
|
||||
@InputType()
|
||||
export class UpdateSettingsInput implements SettingsInput {
|
||||
export class UpdateUserSettingsInput implements UserSettingsInput {
|
||||
@Field({ description: 'Receive invitation email', nullable: true })
|
||||
receiveInvitationEmail?: boolean;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user