@loomcore/api 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,9 +2,9 @@ import { Client } from "pg";
|
|
|
2
2
|
import { IMigration } from "../index.js";
|
|
3
3
|
export declare class CreateAdminUserMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
private readonly
|
|
5
|
+
private readonly adminEmail;
|
|
6
6
|
private readonly adminPassword;
|
|
7
|
-
constructor(client: Client,
|
|
7
|
+
constructor(client: Client, adminEmail: string, adminPassword: string);
|
|
8
8
|
index: number;
|
|
9
9
|
execute(_orgId?: string): Promise<{
|
|
10
10
|
success: boolean;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { PostgresDatabase } from "../index.js";
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { getSystemUserContext, initializeSystemUserContext } from "@loomcore/common/models";
|
|
4
|
+
import { AuthService } from "../../../services/auth.service.js";
|
|
5
5
|
export class CreateAdminUserMigration {
|
|
6
6
|
client;
|
|
7
|
-
|
|
7
|
+
adminEmail;
|
|
8
8
|
adminPassword;
|
|
9
|
-
constructor(client,
|
|
9
|
+
constructor(client, adminEmail, adminPassword) {
|
|
10
10
|
this.client = client;
|
|
11
|
-
this.
|
|
11
|
+
this.adminEmail = adminEmail;
|
|
12
12
|
this.adminPassword = adminPassword;
|
|
13
13
|
}
|
|
14
14
|
index = 6;
|
|
@@ -16,12 +16,13 @@ export class CreateAdminUserMigration {
|
|
|
16
16
|
const _id = randomUUID().toString();
|
|
17
17
|
try {
|
|
18
18
|
const database = new PostgresDatabase(this.client);
|
|
19
|
-
const
|
|
19
|
+
const authService = new AuthService(database);
|
|
20
|
+
initializeSystemUserContext(this.adminEmail, _orgId);
|
|
20
21
|
const systemUserContext = getSystemUserContext();
|
|
21
|
-
const adminUser = await
|
|
22
|
+
const adminUser = await authService.createUser(systemUserContext, {
|
|
22
23
|
_id: _id,
|
|
23
24
|
_orgId: _orgId,
|
|
24
|
-
email: this.
|
|
25
|
+
email: this.adminEmail,
|
|
25
26
|
password: this.adminPassword,
|
|
26
27
|
firstName: 'Admin',
|
|
27
28
|
lastName: 'User',
|
|
@@ -20,7 +20,7 @@ export declare class AuthService extends GenericApiService<IUser> {
|
|
|
20
20
|
} | null>;
|
|
21
21
|
getUserById(id: string): Promise<IUser | null>;
|
|
22
22
|
getUserByEmail(email: string): Promise<IUser | null>;
|
|
23
|
-
createUser(userContext: IUserContext, user: IUser): Promise<IUser | null>;
|
|
23
|
+
createUser(userContext: IUserContext, user: Partial<IUser>): Promise<IUser | null>;
|
|
24
24
|
requestTokenUsingRefreshToken(req: Request): Promise<ITokenResponse | null>;
|
|
25
25
|
changeLoggedInUsersPassword(userContext: IUserContext, body: any): Promise<UpdateResult>;
|
|
26
26
|
changePassword(userContext: IUserContext, queryObject: any, password: string): Promise<UpdateResult>;
|