@open-kingdom/shared-backend-data-access-users 0.0.2-7 → 0.0.2-8

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.
@@ -78,43 +78,6 @@ export declare const users: t.SQLiteTableWithColumns<{
78
78
  }, {}, {
79
79
  length: undefined;
80
80
  }>;
81
- invitedBy: t.SQLiteColumn<{
82
- name: "invited_by";
83
- tableName: "users";
84
- dataType: "number";
85
- columnType: "SQLiteInteger";
86
- data: number;
87
- driverParam: number;
88
- notNull: false;
89
- hasDefault: false;
90
- isPrimaryKey: false;
91
- isAutoincrement: false;
92
- hasRuntimeDefault: false;
93
- enumValues: undefined;
94
- baseColumn: never;
95
- identity: undefined;
96
- generated: undefined;
97
- }, {}, {}>;
98
- role: t.SQLiteColumn<{
99
- name: "role";
100
- tableName: "users";
101
- dataType: "string";
102
- columnType: "SQLiteText";
103
- data: "guest" | "user" | "admin";
104
- driverParam: string;
105
- notNull: false;
106
- hasDefault: true;
107
- isPrimaryKey: false;
108
- isAutoincrement: false;
109
- hasRuntimeDefault: false;
110
- enumValues: [string, ...string[]];
111
- baseColumn: never;
112
- identity: undefined;
113
- generated: undefined;
114
- }, {}, {
115
- length: undefined;
116
- $type: "guest" | "user" | "admin";
117
- }>;
118
81
  password: t.SQLiteColumn<{
119
82
  name: "password";
120
83
  tableName: "users";
@@ -1 +1 @@
1
- {"version":3,"file":"users.schema.d.ts","sourceRoot":"","sources":["../../../src/lib/schemas/users.schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,yBAAyB,CAAC;AAG7C,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQhB,CAAC;AAEH,MAAM,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,YAAY,CAAC;AAC7C,MAAM,MAAM,OAAO,GAAG,OAAO,KAAK,CAAC,YAAY,CAAC"}
1
+ {"version":3,"file":"users.schema.d.ts","sourceRoot":"","sources":["../../../src/lib/schemas/users.schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,yBAAyB,CAAC;AAE7C,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMhB,CAAC;AAEH,MAAM,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,YAAY,CAAC;AAC7C,MAAM,MAAM,OAAO,GAAG,OAAO,KAAK,CAAC,YAAY,CAAC"}
@@ -10,7 +10,5 @@ exports.users = (0, sqlite_core_1.sqliteTable)(exports.UsersTableName, {
10
10
  firstName: t.text('first_name'),
11
11
  lastName: t.text('last_name'),
12
12
  email: t.text().notNull().unique(),
13
- invitedBy: t.int('invited_by').references(() => exports.users.id),
14
- role: t.text().$type().default('guest'),
15
13
  password: t.text().notNull(),
16
14
  });
@@ -9,13 +9,15 @@ export declare class UsersService implements OnModuleInit {
9
9
  constructor(db: BetterSQLite3Database<schema>);
10
10
  onModuleInit(): Promise<void>;
11
11
  findOne(email: string): Promise<User | undefined>;
12
+ findById(id: number): Promise<User | undefined>;
13
+ findAll(): Promise<User[]>;
14
+ create(data: Omit<User, 'id'>): Promise<User>;
15
+ delete(id: number): Promise<void>;
12
16
  ensureUser(data: Omit<User, 'id'>): Promise<{
13
17
  id: number;
14
18
  firstName: string | null;
15
19
  lastName: string | null;
16
20
  email: string;
17
- invitedBy: number | null;
18
- role: "guest" | "user" | "admin" | null;
19
21
  password: string;
20
22
  } | undefined>;
21
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"users.service.d.ts","sourceRoot":"","sources":["../../src/lib/users.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAKnE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAExD,KAAK,MAAM,GAAG;IACZ,CAAC,cAAc,CAAC,EAAE,OAAO,KAAK,CAAC;CAChC,CAAC;AAEF,qBACa,YAAa,YAAW,YAAY;IACnB,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,qBAAqB,CAAC,MAAM,CAAC;IAE/D,YAAY;IAWZ,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;IAOjD,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC;;;;;;;;;CAaxC"}
1
+ {"version":3,"file":"users.service.d.ts","sourceRoot":"","sources":["../../src/lib/users.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAKnE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAExD,KAAK,MAAM,GAAG;IACZ,CAAC,cAAc,CAAC,EAAE,OAAO,KAAK,CAAC;CAChC,CAAC;AAEF,qBACa,YAAa,YAAW,YAAY;IACnB,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,qBAAqB,CAAC,MAAM,CAAC;IAE/D,YAAY;IASZ,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;IAOjD,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;IAO/C,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAI1B,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC;;;;;;;CAYxC"}
@@ -14,12 +14,10 @@ let UsersService = class UsersService {
14
14
  }
15
15
  async onModuleInit() {
16
16
  await this.ensureUser({
17
- invitedBy: null,
18
17
  firstName: 'Admin',
19
18
  lastName: 'Admin',
20
19
  email: 'admin@admin.com',
21
20
  password: 'admin',
22
- role: 'admin',
23
21
  });
24
22
  }
25
23
  async findOne(email) {
@@ -28,6 +26,25 @@ let UsersService = class UsersService {
28
26
  });
29
27
  return user;
30
28
  }
29
+ async findById(id) {
30
+ const user = await this.db.query.users.findFirst({
31
+ where: (0, drizzle_orm_1.eq)(schemas_1.users.id, id),
32
+ });
33
+ return user;
34
+ }
35
+ async findAll() {
36
+ return this.db.query.users.findMany();
37
+ }
38
+ async create(data) {
39
+ await this.db.insert(schemas_1.users).values({
40
+ ...data,
41
+ password: await bcrypt.hash(data.password, 12),
42
+ });
43
+ return this.findOne(data.email);
44
+ }
45
+ async delete(id) {
46
+ await this.db.delete(schemas_1.users).where((0, drizzle_orm_1.eq)(schemas_1.users.id, id));
47
+ }
31
48
  async ensureUser(data) {
32
49
  const existing = await this.findOne(data.email);
33
50
  if (existing)
@@ -37,7 +54,6 @@ let UsersService = class UsersService {
37
54
  lastName: data.lastName,
38
55
  email: data.email,
39
56
  password: await bcrypt.hash(data.password, 12),
40
- role: data.role ?? 'admin',
41
57
  });
42
58
  return this.findOne(data.email);
43
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-kingdom/shared-backend-data-access-users",
3
- "version": "0.0.2-7",
3
+ "version": "0.0.2-8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -10,7 +10,7 @@
10
10
  "exports": {
11
11
  "./package.json": "./package.json",
12
12
  ".": {
13
- "development": "./src/index.ts",
13
+ "@open-kingdom/source": "./src/index.ts",
14
14
  "types": "./dist/index.d.ts",
15
15
  "import": "./dist/index.js",
16
16
  "default": "./dist/index.js"
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "tslib": "^2.3.0",
32
- "@open-kingdom/shared-poly-util-constants": "0.0.2-7",
32
+ "@open-kingdom/shared-poly-util-constants": "0.0.2-8",
33
33
  "@nestjs/common": "^11.0.0",
34
34
  "drizzle-orm": "^0.44.5",
35
35
  "bcrypt": "^5.1.1"