Skip to content

Commit

Permalink
chore: replace systemUser -1 with new -1337 system user
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleek committed Jan 23, 2024
1 parent 0b1d565 commit 283e5bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib/services/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -244,7 +244,12 @@ class UserService {
return userCreated;
}

private getCreatedBy(updatedBy: IUser = systemUser) {
private getCreatedBy(
updatedBy: IUser = new User({
id: SYSTEM_USER.id,
username: SYSTEM_USER.username,
}),
): string {
return updatedBy.username || updatedBy.email;
}

Expand Down Expand Up @@ -444,7 +449,10 @@ class UserService {

async createResetPasswordEmail(
receiverEmail: string,
user: IUser = systemUser,
user: IUser = new User({
id: SYSTEM_USER.id,
username: SYSTEM_USER.username,
}),
): Promise<URL> {
const receiver = await this.getByEmail(receiverEmail);
if (!receiver) {
Expand Down
14 changes: 14 additions & 0 deletions src/migrations/20240123092918-EVENTS-SYSTEM-USER-OLD-TO-NEW.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

exports.up = function (db, callback) {
db.runSql(
`
UPDATE TABLE events SET created_by_user_id = -1337 WHERE created_by_user_id = -1;
`,
callback,
);
};

exports.down = function (db, callback) {
callback();
};

0 comments on commit 283e5bb

Please sign in to comment.