@open-kingdom/shared-backend-data-access-users 0.0.2-6 → 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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './lib/data-access-backend-users.module';
2
- export * from './lib/schema';
3
2
  export * from './lib/users.service';
3
+ export * from './lib/schemas';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./lib/data-access-backend-users.module"), exports);
5
- tslib_1.__exportStar(require("./lib/schema"), exports);
6
5
  tslib_1.__exportStar(require("./lib/users.service"), exports);
6
+ tslib_1.__exportStar(require("./lib/schemas"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './users.schema';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/schemas/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./users.schema"), exports);
@@ -1,5 +1,5 @@
1
1
  import * as t from 'drizzle-orm/sqlite-core';
2
- export declare const UserTableName = "users";
2
+ export declare const UsersTableName = "users";
3
3
  export declare const users: t.SQLiteTableWithColumns<{
4
4
  name: "users";
5
5
  schema: undefined;
@@ -78,43 +78,6 @@ export declare const users: t.SQLiteTableWithColumns<{
78
78
  }, {}, {
79
79
  length: undefined;
80
80
  }>;
81
- invitee: t.SQLiteColumn<{
82
- name: "invitee";
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";
@@ -138,4 +101,5 @@ export declare const users: t.SQLiteTableWithColumns<{
138
101
  dialect: "sqlite";
139
102
  }>;
140
103
  export type User = typeof users.$inferSelect;
141
- //# sourceMappingURL=schema.d.ts.map
104
+ export type NewUser = typeof users.$inferInsert;
105
+ //# sourceMappingURL=users.schema.d.ts.map
@@ -0,0 +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;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"}
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.users = exports.UserTableName = void 0;
3
+ exports.users = exports.UsersTableName = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const sqlite_core_1 = require("drizzle-orm/sqlite-core");
6
6
  const t = tslib_1.__importStar(require("drizzle-orm/sqlite-core"));
7
- exports.UserTableName = 'users';
8
- exports.users = (0, sqlite_core_1.sqliteTable)(exports.UserTableName, {
7
+ exports.UsersTableName = 'users';
8
+ exports.users = (0, sqlite_core_1.sqliteTable)(exports.UsersTableName, {
9
9
  id: t.int().primaryKey({ autoIncrement: true }),
10
10
  firstName: t.text('first_name'),
11
11
  lastName: t.text('last_name'),
12
12
  email: t.text().notNull().unique(),
13
- invitee: t.int().references(() => exports.users.id),
14
- role: t.text().$type().default('guest'),
15
13
  password: t.text().notNull(),
16
- }, (table) => [t.uniqueIndex('email_idx').on(table.email)]);
14
+ });
@@ -1,21 +1,23 @@
1
1
  import { OnModuleInit } from '@nestjs/common';
2
2
  import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
3
- import { User, users, UserTableName } from './schema';
3
+ import { User, users, UsersTableName } from './schemas';
4
4
  type schema = {
5
- [UserTableName]: typeof users;
5
+ [UsersTableName]: typeof users;
6
6
  };
7
7
  export declare class UsersService implements OnModuleInit {
8
8
  private db;
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
- invitee: 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;AAMnE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEtD,KAAK,MAAM,GAAG;IACZ,CAAC,aAAa,CAAC,EAAE,OAAO,KAAK,CAAC;CAC/B,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"}
@@ -7,37 +7,53 @@ const better_sqlite3_1 = require("drizzle-orm/better-sqlite3");
7
7
  const drizzle_orm_1 = require("drizzle-orm");
8
8
  const bcrypt = tslib_1.__importStar(require("bcrypt"));
9
9
  const shared_poly_util_constants_1 = require("@open-kingdom/shared-poly-util-constants");
10
- const schema_1 = require("./schema");
10
+ const schemas_1 = require("./schemas");
11
11
  let UsersService = class UsersService {
12
12
  constructor(db) {
13
13
  this.db = db;
14
14
  }
15
15
  async onModuleInit() {
16
16
  await this.ensureUser({
17
- invitee: 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) {
26
24
  const user = await this.db.query.users.findFirst({
27
- where: (0, drizzle_orm_1.eq)(schema_1.users.email, email),
25
+ where: (0, drizzle_orm_1.eq)(schemas_1.users.email, email),
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)
34
51
  return existing;
35
- await this.db.insert(schema_1.users).values({
52
+ await this.db.insert(schemas_1.users).values({
36
53
  firstName: data.firstName,
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-6",
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
- "@knaadh/nestjs-drizzle-better-sqlite3": "^1.2.0",
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"
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/lib/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,yBAAyB,CAAC;AAG7C,eAAO,MAAM,aAAa,UAAU,CAAC;AACrC,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYjB,CAAC;AACF,MAAM,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,YAAY,CAAC"}