diff --git a/src/lib/services/user-service.ts b/src/lib/services/user-service.ts index 60d83cca8b..323439626e 100644 --- a/src/lib/services/user-service.ts +++ b/src/lib/services/user-service.ts @@ -33,7 +33,7 @@ import { TokenUserSchema } from '../openapi/spec/token-user-schema'; import PasswordMismatch from '../error/password-mismatch'; import EventService from '../features/events/event-service'; -const systemUser = new User({ id: -1, username: 'system' }); +import { SYSTEM_USER } from '../types'; export interface ICreateUser { name?: string; @@ -244,7 +244,7 @@ class UserService { return userCreated; } - private getCreatedBy(updatedBy: IUser = systemUser) { + private getCreatedBy(updatedBy: IUser = new User(SYSTEM_USER)): string { return updatedBy.username || updatedBy.email; } @@ -444,7 +444,10 @@ class UserService { async createResetPasswordEmail( receiverEmail: string, - user: IUser = systemUser, + user: IUser = new User({ + id: SYSTEM_USER.id, + username: SYSTEM_USER.username, + }), ): Promise { const receiver = await this.getByEmail(receiverEmail); if (!receiver) { diff --git a/src/migrations/20240125100000-events-system-user-old2new.js b/src/migrations/20240125100000-events-system-user-old2new.js new file mode 100644 index 0000000000..e1e69e3d77 --- /dev/null +++ b/src/migrations/20240125100000-events-system-user-old2new.js @@ -0,0 +1,14 @@ +'use strict'; + +exports.up = function (db, callback) { + db.runSql( + ` + UPDATE events SET created_by_user_id = -1337 WHERE created_by_user_id = -1; + `, + callback, + ); +}; + +exports.down = function (db, callback) { + callback(); +};