lapeh 2.6.2 → 2.6.5

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/bin/index.js CHANGED
@@ -380,7 +380,16 @@ async function upgradeProject() {
380
380
  ...templatePackageJson.devDependencies
381
381
  };
382
382
 
383
- currentPackageJson.dependencies["lapeh"] = "file:../";
383
+ const frameworkPackageJson = require(path.join(templateDir, 'package.json'));
384
+ if (__dirname.includes('node_modules')) {
385
+ currentPackageJson.dependencies["lapeh"] = `^${frameworkPackageJson.version}`;
386
+ } else {
387
+ const lapehPath = path.resolve(__dirname, '..').replace(/\\/g, '/');
388
+ // Only use file path if we are in local dev environment
389
+ // But for upgrade, we might want to keep existing unless we are sure
390
+ // For now, let's assume if not in node_modules, we want to link to this CLI's source
391
+ currentPackageJson.dependencies["lapeh"] = `file:${lapehPath}`;
392
+ }
384
393
 
385
394
  fs.writeFileSync(packageJsonPath, JSON.stringify(currentPackageJson, null, 2));
386
395
 
@@ -389,7 +398,7 @@ async function upgradeProject() {
389
398
  if (fs.existsSync(tsconfigPath)) {
390
399
  const tsconfig = require(tsconfigPath);
391
400
  if (tsconfig.compilerOptions && tsconfig.compilerOptions.paths) {
392
- tsconfig.compilerOptions.paths["@lapeh/*"] = ["./node_modules/lapeh/lib/*"];
401
+ tsconfig.compilerOptions.paths["@lapeh/*"] = ["./node_modules/lapeh/dist/lib/*"];
393
402
  }
394
403
  tsconfig["ts-node"] = {
395
404
  "ignore": ["node_modules/(?!lapeh)"]
@@ -1,3 +1,4 @@
1
- declare const prisma: any;
1
+ import { PrismaClient } from "@prisma/client";
2
+ declare const prisma: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/client").DefaultArgs>;
2
3
  export { prisma };
3
4
  //# sourceMappingURL=database.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../lib/core/database.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,MAAM,KAMV,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,CAAC"}
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../lib/core/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,QAAA,MAAM,MAAM,+HAAqB,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,CAAC"}
@@ -1,12 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prisma = void 0;
4
- const { PrismaClient } = require("@prisma/client");
5
- const prisma = new PrismaClient({
6
- datasources: {
7
- db: {
8
- url: process.env.DATABASE_URL,
9
- },
10
- },
11
- });
4
+ const client_1 = require("@prisma/client");
5
+ const prisma = new client_1.PrismaClient();
12
6
  exports.prisma = prisma;
@@ -190,7 +190,7 @@ async function me(req, res) {
190
190
  return;
191
191
  }
192
192
  const user = await database_1.prisma.users.findUnique({
193
- where: { id: BigInt(payload.userId) },
193
+ where: { id: payload.userId },
194
194
  include: {
195
195
  user_roles: {
196
196
  include: {
@@ -247,7 +247,7 @@ async function refreshToken(req, res) {
247
247
  return;
248
248
  }
249
249
  const user = await database_1.prisma.users.findUnique({
250
- where: { id: BigInt(decoded.userId) },
250
+ where: { id: decoded.userId },
251
251
  include: {
252
252
  user_roles: {
253
253
  include: {
@@ -303,7 +303,7 @@ async function updateAvatar(req, res) {
303
303
  (0, response_1.sendError)(res, 400, "Avatar file is required");
304
304
  return;
305
305
  }
306
- const userId = BigInt(payload.userId);
306
+ const userId = payload.userId;
307
307
  const avatar = file.filename;
308
308
  const avatar_url = process.env.AVATAR_BASE_URL || `/uploads/avatars/${file.filename}`;
309
309
  const updated = await database_1.prisma.users.update({
@@ -348,7 +348,7 @@ async function updatePassword(req, res) {
348
348
  }
349
349
  const { currentPassword, newPassword } = await validator.validated();
350
350
  const user = await database_1.prisma.users.findUnique({
351
- where: { id: BigInt(payload.userId) },
351
+ where: { id: payload.userId },
352
352
  });
353
353
  if (!user) {
354
354
  (0, response_1.sendError)(res, 404, "User not found");
@@ -391,7 +391,7 @@ async function updateProfile(req, res) {
391
391
  return;
392
392
  }
393
393
  const { name, email } = await validator.validated();
394
- const userId = BigInt(payload.userId);
394
+ const userId = payload.userId;
395
395
  // Manual unique check removed as it is handled by validator
396
396
  const updated = await database_1.prisma.users.update({
397
397
  where: { id: userId },
@@ -67,7 +67,7 @@ async function index(req, res) {
67
67
  async function show(req, res) {
68
68
  const { id } = req.params;
69
69
  const pet = await database_1.prisma.pets.findUnique({
70
- where: { id: BigInt(id) },
70
+ where: { id: id },
71
71
  });
72
72
  if (!pet) {
73
73
  (0, response_1.sendError)(res, 404, "Pet not found");
@@ -123,7 +123,7 @@ async function update(req, res) {
123
123
  return;
124
124
  }
125
125
  const existing = await database_1.prisma.pets.findUnique({
126
- where: { id: BigInt(id) },
126
+ where: { id: id },
127
127
  });
128
128
  if (!existing) {
129
129
  (0, response_1.sendError)(res, 404, "Pet not found");
@@ -131,7 +131,7 @@ async function update(req, res) {
131
131
  }
132
132
  const validatedData = await validator.validated();
133
133
  const updated = await database_1.prisma.pets.update({
134
- where: { id: BigInt(id) },
134
+ where: { id: id },
135
135
  data: {
136
136
  ...validatedData,
137
137
  updated_at: new Date(),
@@ -150,14 +150,14 @@ async function update(req, res) {
150
150
  async function destroy(req, res) {
151
151
  const { id } = req.params;
152
152
  const existing = await database_1.prisma.pets.findUnique({
153
- where: { id: BigInt(id) },
153
+ where: { id: id },
154
154
  });
155
155
  if (!existing) {
156
156
  (0, response_1.sendError)(res, 404, "Pet not found");
157
157
  return;
158
158
  }
159
159
  await database_1.prisma.pets.delete({
160
- where: { id: BigInt(id) },
160
+ where: { id: id },
161
161
  });
162
162
  (0, response_1.sendSuccess)(res, 200, "Pet deleted successfully", null);
163
163
  }
@@ -88,7 +88,7 @@ async function listRoles(_req, res) {
88
88
  }
89
89
  async function updateRole(req, res) {
90
90
  const { id } = req.params;
91
- const roleId = BigInt(id);
91
+ const roleId = id;
92
92
  const validator = validator_1.Validator.make(req.body || {}, {
93
93
  name: "string",
94
94
  slug: `string|unique:roles,slug,${id}`,
@@ -122,7 +122,7 @@ async function updateRole(req, res) {
122
122
  }
123
123
  async function deleteRole(req, res) {
124
124
  const { id } = req.params;
125
- const roleId = BigInt(id);
125
+ const roleId = id;
126
126
  const role = await database_1.prisma.roles.findUnique({ where: { id: roleId } });
127
127
  if (!role) {
128
128
  (0, response_1.sendError)(res, 404, "Role not found");
@@ -180,7 +180,7 @@ async function listPermissions(_req, res) {
180
180
  }
181
181
  async function updatePermission(req, res) {
182
182
  const { id } = req.params;
183
- const permissionId = BigInt(id);
183
+ const permissionId = id;
184
184
  const validator = validator_1.Validator.make(req.body || {}, {
185
185
  name: "string",
186
186
  slug: `string|unique:permissions,slug,${id}`,
@@ -216,7 +216,7 @@ async function updatePermission(req, res) {
216
216
  }
217
217
  async function deletePermission(req, res) {
218
218
  const { id } = req.params;
219
- const permissionId = BigInt(id);
219
+ const permissionId = id;
220
220
  const permission = await database_1.prisma.permissions.findUnique({
221
221
  where: { id: permissionId },
222
222
  });
@@ -248,14 +248,14 @@ async function assignRoleToUser(req, res) {
248
248
  }
249
249
  const { userId, roleId } = await validator.validated();
250
250
  const user = await database_1.prisma.users.findUnique({
251
- where: { id: BigInt(userId) },
251
+ where: { id: userId },
252
252
  });
253
253
  if (!user) {
254
254
  (0, response_1.sendError)(res, 404, "User not found");
255
255
  return;
256
256
  }
257
257
  const role = await database_1.prisma.roles.findUnique({
258
- where: { id: BigInt(roleId) },
258
+ where: { id: roleId },
259
259
  });
260
260
  if (!role) {
261
261
  (0, response_1.sendError)(res, 404, "Role not found");
@@ -264,13 +264,13 @@ async function assignRoleToUser(req, res) {
264
264
  await database_1.prisma.user_roles.upsert({
265
265
  where: {
266
266
  user_id_role_id: {
267
- user_id: BigInt(userId),
268
- role_id: BigInt(roleId),
267
+ user_id: userId,
268
+ role_id: roleId,
269
269
  },
270
270
  },
271
271
  create: {
272
- user_id: BigInt(userId),
273
- role_id: BigInt(roleId),
272
+ user_id: userId,
273
+ role_id: roleId,
274
274
  created_at: new Date(),
275
275
  },
276
276
  update: {},
@@ -293,8 +293,8 @@ async function removeRoleFromUser(req, res) {
293
293
  const { userId, roleId } = await validator.validated();
294
294
  await database_1.prisma.user_roles.deleteMany({
295
295
  where: {
296
- user_id: BigInt(userId),
297
- role_id: BigInt(roleId),
296
+ user_id: userId,
297
+ role_id: roleId,
298
298
  },
299
299
  });
300
300
  (0, response_1.sendFastSuccess)(res, 200, voidSerializer, {
@@ -314,14 +314,14 @@ async function assignPermissionToRole(req, res) {
314
314
  }
315
315
  const { roleId, permissionId } = await validator.validated();
316
316
  const role = await database_1.prisma.roles.findUnique({
317
- where: { id: BigInt(roleId) },
317
+ where: { id: roleId },
318
318
  });
319
319
  if (!role) {
320
320
  (0, response_1.sendError)(res, 404, "Role not found");
321
321
  return;
322
322
  }
323
323
  const permission = await database_1.prisma.permissions.findUnique({
324
- where: { id: BigInt(permissionId) },
324
+ where: { id: permissionId },
325
325
  });
326
326
  if (!permission) {
327
327
  (0, response_1.sendError)(res, 404, "Permission not found");
@@ -330,13 +330,13 @@ async function assignPermissionToRole(req, res) {
330
330
  await database_1.prisma.role_permissions.upsert({
331
331
  where: {
332
332
  role_id_permission_id: {
333
- role_id: BigInt(roleId),
334
- permission_id: BigInt(permissionId),
333
+ role_id: roleId,
334
+ permission_id: permissionId,
335
335
  },
336
336
  },
337
337
  create: {
338
- role_id: BigInt(roleId),
339
- permission_id: BigInt(permissionId),
338
+ role_id: roleId,
339
+ permission_id: permissionId,
340
340
  created_at: new Date(),
341
341
  },
342
342
  update: {},
@@ -359,8 +359,8 @@ async function removePermissionFromRole(req, res) {
359
359
  const { roleId, permissionId } = await validator.validated();
360
360
  await database_1.prisma.role_permissions.deleteMany({
361
361
  where: {
362
- role_id: BigInt(roleId),
363
- permission_id: BigInt(permissionId),
362
+ role_id: roleId,
363
+ permission_id: permissionId,
364
364
  },
365
365
  });
366
366
  (0, response_1.sendFastSuccess)(res, 200, voidSerializer, {
@@ -380,14 +380,14 @@ async function assignPermissionToUser(req, res) {
380
380
  }
381
381
  const { userId, permissionId } = await validator.validated();
382
382
  const user = await database_1.prisma.users.findUnique({
383
- where: { id: BigInt(userId) },
383
+ where: { id: userId },
384
384
  });
385
385
  if (!user) {
386
386
  (0, response_1.sendError)(res, 404, "User not found");
387
387
  return;
388
388
  }
389
389
  const permission = await database_1.prisma.permissions.findUnique({
390
- where: { id: BigInt(permissionId) },
390
+ where: { id: permissionId },
391
391
  });
392
392
  if (!permission) {
393
393
  (0, response_1.sendError)(res, 404, "Permission not found");
@@ -396,13 +396,13 @@ async function assignPermissionToUser(req, res) {
396
396
  await database_1.prisma.user_permissions.upsert({
397
397
  where: {
398
398
  user_id_permission_id: {
399
- user_id: BigInt(userId),
400
- permission_id: BigInt(permissionId),
399
+ user_id: userId,
400
+ permission_id: permissionId,
401
401
  },
402
402
  },
403
403
  create: {
404
- user_id: BigInt(userId),
405
- permission_id: BigInt(permissionId),
404
+ user_id: userId,
405
+ permission_id: permissionId,
406
406
  created_at: new Date(),
407
407
  },
408
408
  update: {},
@@ -425,8 +425,8 @@ async function removePermissionFromUser(req, res) {
425
425
  const { userId, permissionId } = await validator.validated();
426
426
  await database_1.prisma.user_permissions.deleteMany({
427
427
  where: {
428
- user_id: BigInt(userId),
429
- permission_id: BigInt(permissionId),
428
+ user_id: userId,
429
+ permission_id: permissionId,
430
430
  },
431
431
  });
432
432
  (0, response_1.sendFastSuccess)(res, 200, voidSerializer, {
@@ -1,11 +1,5 @@
1
- const { PrismaClient } = require("@prisma/client");
1
+ import { PrismaClient } from "@prisma/client";
2
2
 
3
- const prisma = new PrismaClient({
4
- datasources: {
5
- db: {
6
- url: process.env.DATABASE_URL,
7
- },
8
- },
9
- });
3
+ const prisma = new PrismaClient();
10
4
 
11
5
  export { prisma };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lapeh",
3
- "version": "2.6.2",
3
+ "version": "2.6.5",
4
4
  "description": "Framework API Express yang siap pakai (Standardized)",
5
5
  "engines": {
6
6
  "node": ">=18.0.0",
@@ -37,7 +37,8 @@
37
37
  "eslint.config.mjs",
38
38
  "prisma.config.ts",
39
39
  "gitignore.template",
40
- "ecosystem.config.js"
40
+ "ecosystem.config.js",
41
+ "tsconfig.build.json"
41
42
  ],
42
43
  "scripts": {
43
44
  "dev": "node bin/index.js dev",
@@ -109,6 +109,9 @@ model users {
109
109
  remember_token String?
110
110
  created_at DateTime?
111
111
  updated_at DateTime?
112
+
113
+ user_roles user_roles[]
114
+ user_permissions user_permissions[]
112
115
  }
113
116
 
114
117
 
@@ -121,3 +124,73 @@ model pets {
121
124
  created_at DateTime?
122
125
  updated_at DateTime?
123
126
  }
127
+
128
+
129
+ model roles {
130
+ id String @id @default(uuid())
131
+ name String
132
+ slug String @unique
133
+ description String?
134
+ created_at DateTime @default(now())
135
+ updated_at DateTime @updatedAt
136
+
137
+ user_roles user_roles[]
138
+ role_permissions role_permissions[]
139
+ }
140
+
141
+ model permissions {
142
+ id String @id @default(uuid())
143
+ name String
144
+ slug String @unique
145
+ description String?
146
+ created_at DateTime @default(now())
147
+ updated_at DateTime @updatedAt
148
+
149
+ role_permissions role_permissions[]
150
+ user_permissions user_permissions[]
151
+ }
152
+
153
+ model user_roles {
154
+ id String @id @default(uuid())
155
+ user_id String
156
+ role_id String
157
+ created_at DateTime @default(now())
158
+ updated_at DateTime @updatedAt
159
+
160
+ user users @relation(fields: [user_id], references: [id], onDelete: Cascade)
161
+ role roles @relation(fields: [role_id], references: [id], onDelete: Cascade)
162
+
163
+ @@unique([user_id, role_id])
164
+ @@index([user_id])
165
+ @@index([role_id])
166
+ }
167
+
168
+ model role_permissions {
169
+ id String @id @default(uuid())
170
+ role_id String
171
+ permission_id String
172
+ created_at DateTime @default(now())
173
+ updated_at DateTime @updatedAt
174
+
175
+ role roles @relation(fields: [role_id], references: [id], onDelete: Cascade)
176
+ permission permissions @relation(fields: [permission_id], references: [id], onDelete: Cascade)
177
+
178
+ @@unique([role_id, permission_id])
179
+ @@index([role_id])
180
+ @@index([permission_id])
181
+ }
182
+
183
+ model user_permissions {
184
+ id String @id @default(uuid())
185
+ user_id String
186
+ permission_id String
187
+ created_at DateTime @default(now())
188
+ updated_at DateTime @updatedAt
189
+
190
+ user users @relation(fields: [user_id], references: [id], onDelete: Cascade)
191
+ permission permissions @relation(fields: [permission_id], references: [id], onDelete: Cascade)
192
+
193
+ @@unique([user_id, permission_id])
194
+ @@index([user_id])
195
+ @@index([permission_id])
196
+ }
package/prisma/seed.ts CHANGED
@@ -263,7 +263,7 @@ async function main() {
263
263
  console.log("Seeded resource permissions");
264
264
 
265
265
  // 4. Assign permissions to roles
266
- const rolePermPairs: { roleId: bigint; permId: bigint }[] = [
266
+ const rolePermPairs: { roleId: string; permId: string }[] = [
267
267
  // super_admin gets all users permissions + other management permissions
268
268
  { roleId: superAdminRole.id, permId: manageUsers.id },
269
269
  { roleId: superAdminRole.id, permId: manageUsersCreate.id },
@@ -316,7 +316,7 @@ async function main() {
316
316
  console.log("Assigned permissions to roles");
317
317
 
318
318
  // 5. Assign roles to users
319
- const userRolePairs: { userId: bigint; roleId: bigint }[] = [
319
+ const userRolePairs: { userId: string; roleId: string }[] = [
320
320
  { userId: superAdmin.id, roleId: superAdminRole.id },
321
321
  { userId: admin.id, roleId: adminRole.id },
322
322
  { userId: user.id, roleId: userRole.id },
package/prisma.config.ts CHANGED
@@ -9,6 +9,6 @@ export default defineConfig({
9
9
  url: process.env.DATABASE_URL,
10
10
  },
11
11
  migrations: {
12
- seed: 'ts-node prisma/seed.ts',
12
+ seed: "ts-node -r tsconfig-paths/register prisma/seed.ts",
13
13
  },
14
14
  });
@@ -219,7 +219,7 @@ export async function me(req: Request, res: Response) {
219
219
  return;
220
220
  }
221
221
  const user = await prisma.users.findUnique({
222
- where: { id: BigInt(payload.userId) },
222
+ where: { id: payload.userId },
223
223
  include: {
224
224
  user_roles: {
225
225
  include: {
@@ -285,7 +285,7 @@ export async function refreshToken(req: Request, res: Response) {
285
285
  return;
286
286
  }
287
287
  const user = await prisma.users.findUnique({
288
- where: { id: BigInt(decoded.userId) },
288
+ where: { id: decoded.userId },
289
289
  include: {
290
290
  user_roles: {
291
291
  include: {
@@ -353,7 +353,7 @@ export async function updateAvatar(req: Request, res: Response) {
353
353
  sendError(res, 400, "Avatar file is required");
354
354
  return;
355
355
  }
356
- const userId = BigInt(payload.userId);
356
+ const userId = payload.userId;
357
357
  const avatar = file.filename;
358
358
  const avatar_url =
359
359
  process.env.AVATAR_BASE_URL || `/uploads/avatars/${file.filename}`;
@@ -401,7 +401,7 @@ export async function updatePassword(req: Request, res: Response) {
401
401
  }
402
402
  const { currentPassword, newPassword } = await validator.validated();
403
403
  const user = await prisma.users.findUnique({
404
- where: { id: BigInt(payload.userId) },
404
+ where: { id: payload.userId },
405
405
  });
406
406
  if (!user) {
407
407
  sendError(res, 404, "User not found");
@@ -445,7 +445,7 @@ export async function updateProfile(req: Request, res: Response) {
445
445
  return;
446
446
  }
447
447
  const { name, email } = await validator.validated();
448
- const userId = BigInt(payload.userId);
448
+ const userId = payload.userId;
449
449
  // Manual unique check removed as it is handled by validator
450
450
 
451
451
  const updated = await prisma.users.update({
@@ -100,4 +100,7 @@ model users {
100
100
  remember_token String?
101
101
  created_at DateTime?
102
102
  updated_at DateTime?
103
+
104
+ user_roles user_roles[]
105
+ user_permissions user_permissions[]
103
106
  }
@@ -81,7 +81,7 @@ export async function index(req: Request, res: Response) {
81
81
  export async function show(req: Request, res: Response) {
82
82
  const { id } = req.params;
83
83
  const pet = await prisma.pets.findUnique({
84
- where: { id: BigInt(id) },
84
+ where: { id: id },
85
85
  });
86
86
 
87
87
  if (!pet) {
@@ -146,7 +146,7 @@ export async function update(req: Request, res: Response) {
146
146
  }
147
147
 
148
148
  const existing = await prisma.pets.findUnique({
149
- where: { id: BigInt(id) },
149
+ where: { id: id },
150
150
  });
151
151
 
152
152
  if (!existing) {
@@ -156,7 +156,7 @@ export async function update(req: Request, res: Response) {
156
156
 
157
157
  const validatedData = await validator.validated();
158
158
  const updated = await prisma.pets.update({
159
- where: { id: BigInt(id) },
159
+ where: { id: id },
160
160
  data: {
161
161
  ...validatedData,
162
162
  updated_at: new Date(),
@@ -178,7 +178,7 @@ export async function destroy(req: Request, res: Response) {
178
178
  const { id } = req.params;
179
179
 
180
180
  const existing = await prisma.pets.findUnique({
181
- where: { id: BigInt(id) },
181
+ where: { id: id },
182
182
  });
183
183
 
184
184
  if (!existing) {
@@ -187,7 +187,7 @@ export async function destroy(req: Request, res: Response) {
187
187
  }
188
188
 
189
189
  await prisma.pets.delete({
190
- where: { id: BigInt(id) },
190
+ where: { id: id },
191
191
  });
192
192
 
193
193
  sendSuccess(res, 200, "Pet deleted successfully", null);
@@ -98,7 +98,7 @@ export async function listRoles(_req: Request, res: Response) {
98
98
 
99
99
  export async function updateRole(req: Request, res: Response) {
100
100
  const { id } = req.params;
101
- const roleId = BigInt(id);
101
+ const roleId = id;
102
102
 
103
103
  const validator = Validator.make(req.body || {}, {
104
104
  name: "string",
@@ -136,7 +136,7 @@ export async function updateRole(req: Request, res: Response) {
136
136
 
137
137
  export async function deleteRole(req: Request, res: Response) {
138
138
  const { id } = req.params;
139
- const roleId = BigInt(id);
139
+ const roleId = id;
140
140
  const role = await prisma.roles.findUnique({ where: { id: roleId } });
141
141
  if (!role) {
142
142
  sendError(res, 404, "Role not found");
@@ -199,7 +199,7 @@ export async function listPermissions(_req: Request, res: Response) {
199
199
 
200
200
  export async function updatePermission(req: Request, res: Response) {
201
201
  const { id } = req.params;
202
- const permissionId = BigInt(id);
202
+ const permissionId = id;
203
203
 
204
204
  const validator = Validator.make(req.body || {}, {
205
205
  name: "string",
@@ -239,7 +239,7 @@ export async function updatePermission(req: Request, res: Response) {
239
239
 
240
240
  export async function deletePermission(req: Request, res: Response) {
241
241
  const { id } = req.params;
242
- const permissionId = BigInt(id);
242
+ const permissionId = id;
243
243
  const permission = await prisma.permissions.findUnique({
244
244
  where: { id: permissionId },
245
245
  });
@@ -274,14 +274,14 @@ export async function assignRoleToUser(req: Request, res: Response) {
274
274
  const { userId, roleId } = await validator.validated();
275
275
 
276
276
  const user = await prisma.users.findUnique({
277
- where: { id: BigInt(userId) },
277
+ where: { id: userId },
278
278
  });
279
279
  if (!user) {
280
280
  sendError(res, 404, "User not found");
281
281
  return;
282
282
  }
283
283
  const role = await prisma.roles.findUnique({
284
- where: { id: BigInt(roleId) },
284
+ where: { id: roleId },
285
285
  });
286
286
  if (!role) {
287
287
  sendError(res, 404, "Role not found");
@@ -290,13 +290,13 @@ export async function assignRoleToUser(req: Request, res: Response) {
290
290
  await prisma.user_roles.upsert({
291
291
  where: {
292
292
  user_id_role_id: {
293
- user_id: BigInt(userId),
294
- role_id: BigInt(roleId),
293
+ user_id: userId,
294
+ role_id: roleId,
295
295
  },
296
296
  },
297
297
  create: {
298
- user_id: BigInt(userId),
299
- role_id: BigInt(roleId),
298
+ user_id: userId,
299
+ role_id: roleId,
300
300
  created_at: new Date(),
301
301
  },
302
302
  update: {},
@@ -322,8 +322,8 @@ export async function removeRoleFromUser(req: Request, res: Response) {
322
322
 
323
323
  await prisma.user_roles.deleteMany({
324
324
  where: {
325
- user_id: BigInt(userId),
326
- role_id: BigInt(roleId),
325
+ user_id: userId,
326
+ role_id: roleId,
327
327
  },
328
328
  });
329
329
  sendFastSuccess(res, 200, voidSerializer, {
@@ -346,14 +346,14 @@ export async function assignPermissionToRole(req: Request, res: Response) {
346
346
  const { roleId, permissionId } = await validator.validated();
347
347
 
348
348
  const role = await prisma.roles.findUnique({
349
- where: { id: BigInt(roleId) },
349
+ where: { id: roleId },
350
350
  });
351
351
  if (!role) {
352
352
  sendError(res, 404, "Role not found");
353
353
  return;
354
354
  }
355
355
  const permission = await prisma.permissions.findUnique({
356
- where: { id: BigInt(permissionId) },
356
+ where: { id: permissionId },
357
357
  });
358
358
  if (!permission) {
359
359
  sendError(res, 404, "Permission not found");
@@ -362,13 +362,13 @@ export async function assignPermissionToRole(req: Request, res: Response) {
362
362
  await prisma.role_permissions.upsert({
363
363
  where: {
364
364
  role_id_permission_id: {
365
- role_id: BigInt(roleId),
366
- permission_id: BigInt(permissionId),
365
+ role_id: roleId,
366
+ permission_id: permissionId,
367
367
  },
368
368
  },
369
369
  create: {
370
- role_id: BigInt(roleId),
371
- permission_id: BigInt(permissionId),
370
+ role_id: roleId,
371
+ permission_id: permissionId,
372
372
  created_at: new Date(),
373
373
  },
374
374
  update: {},
@@ -394,8 +394,8 @@ export async function removePermissionFromRole(req: Request, res: Response) {
394
394
 
395
395
  await prisma.role_permissions.deleteMany({
396
396
  where: {
397
- role_id: BigInt(roleId),
398
- permission_id: BigInt(permissionId),
397
+ role_id: roleId,
398
+ permission_id: permissionId,
399
399
  },
400
400
  });
401
401
  sendFastSuccess(res, 200, voidSerializer, {
@@ -418,14 +418,14 @@ export async function assignPermissionToUser(req: Request, res: Response) {
418
418
  const { userId, permissionId } = await validator.validated();
419
419
 
420
420
  const user = await prisma.users.findUnique({
421
- where: { id: BigInt(userId) },
421
+ where: { id: userId },
422
422
  });
423
423
  if (!user) {
424
424
  sendError(res, 404, "User not found");
425
425
  return;
426
426
  }
427
427
  const permission = await prisma.permissions.findUnique({
428
- where: { id: BigInt(permissionId) },
428
+ where: { id: permissionId },
429
429
  });
430
430
  if (!permission) {
431
431
  sendError(res, 404, "Permission not found");
@@ -434,13 +434,13 @@ export async function assignPermissionToUser(req: Request, res: Response) {
434
434
  await prisma.user_permissions.upsert({
435
435
  where: {
436
436
  user_id_permission_id: {
437
- user_id: BigInt(userId),
438
- permission_id: BigInt(permissionId),
437
+ user_id: userId,
438
+ permission_id: permissionId,
439
439
  },
440
440
  },
441
441
  create: {
442
- user_id: BigInt(userId),
443
- permission_id: BigInt(permissionId),
442
+ user_id: userId,
443
+ permission_id: permissionId,
444
444
  created_at: new Date(),
445
445
  },
446
446
  update: {},
@@ -466,8 +466,8 @@ export async function removePermissionFromUser(req: Request, res: Response) {
466
466
 
467
467
  await prisma.user_permissions.deleteMany({
468
468
  where: {
469
- user_id: BigInt(userId),
470
- permission_id: BigInt(permissionId),
469
+ user_id: userId,
470
+ permission_id: permissionId,
471
471
  },
472
472
  });
473
473
  sendFastSuccess(res, 200, voidSerializer, {
@@ -0,0 +1,68 @@
1
+ model roles {
2
+ id String @id @default(auto()) @map("_id") @db.ObjectId
3
+ name String
4
+ slug String @unique
5
+ description String?
6
+ created_at DateTime @default(now())
7
+ updated_at DateTime @updatedAt
8
+
9
+ user_roles user_roles[]
10
+ role_permissions role_permissions[]
11
+ }
12
+
13
+ model permissions {
14
+ id String @id @default(auto()) @map("_id") @db.ObjectId
15
+ name String
16
+ slug String @unique
17
+ description String?
18
+ created_at DateTime @default(now())
19
+ updated_at DateTime @updatedAt
20
+
21
+ role_permissions role_permissions[]
22
+ user_permissions user_permissions[]
23
+ }
24
+
25
+ model user_roles {
26
+ id String @id @default(auto()) @map("_id") @db.ObjectId
27
+ user_id String @db.ObjectId
28
+ role_id String @db.ObjectId
29
+ created_at DateTime @default(now())
30
+ updated_at DateTime @updatedAt
31
+
32
+ user users @relation(fields: [user_id], references: [id], onDelete: Cascade)
33
+ role roles @relation(fields: [role_id], references: [id], onDelete: Cascade)
34
+
35
+ @@unique([user_id, role_id])
36
+ @@index([user_id])
37
+ @@index([role_id])
38
+ }
39
+
40
+ model role_permissions {
41
+ id String @id @default(auto()) @map("_id") @db.ObjectId
42
+ role_id String @db.ObjectId
43
+ permission_id String @db.ObjectId
44
+ created_at DateTime @default(now())
45
+ updated_at DateTime @updatedAt
46
+
47
+ role roles @relation(fields: [role_id], references: [id], onDelete: Cascade)
48
+ permission permissions @relation(fields: [permission_id], references: [id], onDelete: Cascade)
49
+
50
+ @@unique([role_id, permission_id])
51
+ @@index([role_id])
52
+ @@index([permission_id])
53
+ }
54
+
55
+ model user_permissions {
56
+ id String @id @default(auto()) @map("_id") @db.ObjectId
57
+ user_id String @db.ObjectId
58
+ permission_id String @db.ObjectId
59
+ created_at DateTime @default(now())
60
+ updated_at DateTime @updatedAt
61
+
62
+ user users @relation(fields: [user_id], references: [id], onDelete: Cascade)
63
+ permission permissions @relation(fields: [permission_id], references: [id], onDelete: Cascade)
64
+
65
+ @@unique([user_id, permission_id])
66
+ @@index([user_id])
67
+ @@index([permission_id])
68
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": [
4
+ "lib",
5
+ "src",
6
+ "prisma",
7
+ "generated"
8
+ ],
9
+ "exclude": [
10
+ "node_modules",
11
+ "dist",
12
+ "tests"
13
+ ]
14
+ }