* use jwt to reset password * increase expiration time to 1d * drop user id query string * refactor * use service instead of package in tests * sqlite migration * postgres migration * mysql migration * remove unused properties * remove userId from FE * fix test for users.api * move migration to the common folder * move type assertion to the jwt.service * Add jwt secret as a readonly property * use signData instead of sign in user.controller * remove base class * remove base class * add tests
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import type { EntityManager, FindOptionsWhere } from 'typeorm';
|
|
import { In } from 'typeorm';
|
|
import * as Db from '@/Db';
|
|
import { User } from '@db/entities/User';
|
|
import type { IUserSettings } from 'n8n-workflow';
|
|
|
|
export class UserService {
|
|
static async get(where: FindOptionsWhere<User>): Promise<User | null> {
|
|
return Db.collections.User.findOne({
|
|
relations: ['globalRole'],
|
|
where,
|
|
});
|
|
}
|
|
|
|
static async getByIds(transaction: EntityManager, ids: string[]) {
|
|
return transaction.find(User, { where: { id: In(ids) } });
|
|
}
|
|
|
|
static async updateUserSettings(id: string, userSettings: Partial<IUserSettings>) {
|
|
const { settings: currentSettings } = await Db.collections.User.findOneOrFail({
|
|
where: { id },
|
|
});
|
|
return Db.collections.User.update(id, { settings: { ...currentSettings, ...userSettings } });
|
|
}
|
|
|
|
static async generatePasswordResetUrl(instanceBaseUrl: string, token: string): Promise<string> {
|
|
const url = new URL(`${instanceBaseUrl}/change-password`);
|
|
url.searchParams.append('token', token);
|
|
return url.toString();
|
|
}
|
|
}
|