@skroz/profile-api 1.0.8 → 1.0.9

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.
@@ -1,7 +1,8 @@
1
1
  import { AuthUser, ProfileDbAdapter } from '../types';
2
2
  export declare class TypeOrmProfileAdapter implements ProfileDbAdapter {
3
- private repository;
4
- constructor(userEntity: any);
3
+ private getRepository;
4
+ constructor(getRepository: () => any);
5
+ private get repo();
5
6
  findUserByEmail(email: string): Promise<AuthUser | null>;
6
7
  findUserById(id: number): Promise<AuthUser | null>;
7
8
  findUserByTelegramId(telegramId: string): Promise<AuthUser | null>;
@@ -12,32 +12,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TypeOrmProfileAdapter = void 0;
13
13
  const typeorm_1 = require("typeorm");
14
14
  class TypeOrmProfileAdapter {
15
- constructor(userEntity) {
16
- this.repository = (0, typeorm_1.getConnection)().getRepository(userEntity);
15
+ constructor(getRepository) {
16
+ this.getRepository = getRepository;
17
+ }
18
+ get repo() {
19
+ return this.getRepository();
17
20
  }
18
21
  findUserByEmail(email) {
19
22
  return __awaiter(this, void 0, void 0, function* () {
20
- return this.repository.findOne({ where: { email: email.toLowerCase() } });
23
+ return this.repo.findOne({ where: { email: email.toLowerCase() } });
21
24
  });
22
25
  }
23
26
  findUserById(id) {
24
27
  return __awaiter(this, void 0, void 0, function* () {
25
- return this.repository.findOne(id);
28
+ return this.repo.findOne(id);
26
29
  });
27
30
  }
28
31
  findUserByTelegramId(telegramId) {
29
32
  return __awaiter(this, void 0, void 0, function* () {
30
- return this.repository.findOne({ where: { telegramId } });
33
+ return this.repo.findOne({ where: { telegramId } });
31
34
  });
32
35
  }
33
36
  createUser(data) {
34
37
  return __awaiter(this, void 0, void 0, function* () {
35
- const user = this.repository.create({
38
+ const user = this.repo.create({
36
39
  email: data.email.toLowerCase(),
37
40
  password: data.passwordHash,
38
41
  isEmailConfirmed: false,
39
42
  });
40
- return (yield this.repository.save(user));
43
+ return (yield this.repo.save(user));
41
44
  });
42
45
  }
43
46
  isEmailTaken(email, excludeUserId) {
@@ -46,7 +49,7 @@ class TypeOrmProfileAdapter {
46
49
  if (excludeUserId) {
47
50
  where.id = (0, typeorm_1.Not)(excludeUserId);
48
51
  }
49
- const count = yield this.repository.count({ where });
52
+ const count = yield this.repo.count({ where });
50
53
  return count > 0;
51
54
  });
52
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skroz/profile-api",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "license": "MIT",
5
5
  "repository": "git@gitlab.com:skroz/libs/utils.git",
6
6
  "main": "dist/index.js",
@@ -27,9 +27,7 @@
27
27
  "argon2": "0.30.2",
28
28
  "class-validator": "0.13.2",
29
29
  "nanoid": "3.3.4",
30
- "pug": "3.0.2",
31
- "type-graphql": "2.0.0-beta.1",
32
- "typeorm": "0.2.45"
30
+ "pug": "3.0.2"
33
31
  },
34
32
  "devDependencies": {
35
33
  "@types/node": "18.0.6",
@@ -39,7 +37,9 @@
39
37
  "typescript": "^5.0.0"
40
38
  },
41
39
  "peerDependencies": {
42
- "reflect-metadata": "0.1.13"
40
+ "reflect-metadata": "0.1.13",
41
+ "type-graphql": "^1.1.1",
42
+ "typeorm": "^0.2.45"
43
43
  },
44
- "gitHead": "0c03e4bb82b77e9309550c90871cec3971972e6b"
44
+ "gitHead": "3208ed23610d456e63fddd636448fe4585adf401"
45
45
  }
@@ -1,32 +1,32 @@
1
- import { Repository, getConnection, Not } from 'typeorm';
1
+ import { Repository, Not } from 'typeorm';
2
2
  import { AuthUser, ProfileDbAdapter } from '../types';
3
3
 
4
4
  export class TypeOrmProfileAdapter implements ProfileDbAdapter {
5
- private repository: Repository<any>;
5
+ constructor(private getRepository: () => any) { }
6
6
 
7
- constructor(userEntity: any) {
8
- this.repository = getConnection().getRepository(userEntity);
7
+ private get repo(): Repository<any> {
8
+ return this.getRepository();
9
9
  }
10
10
 
11
11
  async findUserByEmail(email: string): Promise<AuthUser | null> {
12
- return this.repository.findOne({ where: { email: email.toLowerCase() } }) as Promise<AuthUser | null>;
12
+ return this.repo.findOne({ where: { email: email.toLowerCase() } }) as Promise<AuthUser | null>;
13
13
  }
14
14
 
15
15
  async findUserById(id: number): Promise<AuthUser | null> {
16
- return this.repository.findOne(id) as Promise<AuthUser | null>;
16
+ return this.repo.findOne(id) as Promise<AuthUser | null>;
17
17
  }
18
18
 
19
19
  async findUserByTelegramId(telegramId: string): Promise<AuthUser | null> {
20
- return this.repository.findOne({ where: { telegramId } }) as Promise<AuthUser | null>;
20
+ return this.repo.findOne({ where: { telegramId } }) as Promise<AuthUser | null>;
21
21
  }
22
22
 
23
23
  async createUser(data: { email: string; passwordHash: string }): Promise<AuthUser> {
24
- const user = this.repository.create({
24
+ const user = this.repo.create({
25
25
  email: data.email.toLowerCase(),
26
26
  password: data.passwordHash,
27
27
  isEmailConfirmed: false,
28
28
  });
29
- return (await this.repository.save(user)) as AuthUser;
29
+ return (await this.repo.save(user)) as AuthUser;
30
30
  }
31
31
 
32
32
  async isEmailTaken(email: string, excludeUserId?: number): Promise<boolean> {
@@ -34,7 +34,7 @@ export class TypeOrmProfileAdapter implements ProfileDbAdapter {
34
34
  if (excludeUserId) {
35
35
  where.id = Not(excludeUserId);
36
36
  }
37
- const count = await this.repository.count({ where });
37
+ const count = await this.repo.count({ where });
38
38
  return count > 0;
39
39
  }
40
40
  }