@sundaysf/cli-v2 0.0.4 → 1.0.1

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.
Files changed (50) hide show
  1. package/README.md +178 -178
  2. package/dist/README.md +178 -178
  3. package/dist/bin/generators/class.js.map +1 -1
  4. package/dist/bin/generators/postman.js.map +1 -1
  5. package/dist/bin/index.js.map +1 -1
  6. package/dist/templates/backend/.env.example +13 -13
  7. package/dist/templates/backend/.prettierignore +2 -2
  8. package/dist/templates/backend/Dockerfile +14 -14
  9. package/dist/templates/backend/README.md +18 -18
  10. package/dist/templates/backend/src/app.ts +34 -34
  11. package/dist/templates/backend/src/common/utils/environment.resolver.ts +3 -3
  12. package/dist/templates/backend/src/common/utils/version.resolver.ts +4 -4
  13. package/dist/templates/backend/src/controllers/health/health.controller.ts +23 -23
  14. package/dist/templates/backend/src/routes/health/health.router.ts +16 -16
  15. package/dist/templates/backend/src/routes/index.ts +57 -57
  16. package/dist/templates/backend/src/server.ts +16 -16
  17. package/dist/templates/backend/src/types.d.ts +10 -10
  18. package/dist/templates/backend-db-sql/.env.example +14 -13
  19. package/dist/templates/backend-db-sql/.prettierignore +2 -2
  20. package/dist/templates/backend-db-sql/Dockerfile +17 -17
  21. package/dist/templates/backend-db-sql/README.md +34 -34
  22. package/dist/templates/backend-db-sql/db/knexfile.ts +33 -33
  23. package/dist/templates/backend-db-sql/db/migrations/001_create_sundays_package_version.ts +12 -12
  24. package/dist/templates/backend-db-sql/db/seeds/001_sundays_package_version_seed.ts +10 -10
  25. package/dist/templates/backend-db-sql/db/src/KnexConnection.ts +74 -74
  26. package/dist/templates/backend-db-sql/db/src/d.types.ts +18 -18
  27. package/dist/templates/backend-db-sql/db/src/dao/sundays-package-version/sundays-package-version.dao.ts +71 -71
  28. package/dist/templates/backend-db-sql/db/src/index.ts +9 -9
  29. package/dist/templates/backend-db-sql/db/src/interfaces/sundays-package-version/sundays-package-version.interfaces.ts +6 -6
  30. package/dist/templates/backend-db-sql/db/tsconfig.json +16 -16
  31. package/dist/templates/backend-db-sql/src/app.ts +34 -34
  32. package/dist/templates/backend-db-sql/src/common/utils/environment.resolver.ts +3 -3
  33. package/dist/templates/backend-db-sql/src/common/utils/version.resolver.ts +4 -4
  34. package/dist/templates/backend-db-sql/src/controllers/health/health.controller.ts +23 -23
  35. package/dist/templates/backend-db-sql/src/routes/health/health.router.ts +16 -16
  36. package/dist/templates/backend-db-sql/src/routes/index.ts +57 -57
  37. package/dist/templates/backend-db-sql/src/server.ts +18 -18
  38. package/dist/templates/backend-db-sql/src/types.d.ts +10 -10
  39. package/dist/templates/db-sql/knexfile.ts +33 -33
  40. package/dist/templates/db-sql/migrations/001_create_sundays_package_version.ts +12 -12
  41. package/dist/templates/db-sql/seeds/001_sundays_package_version_seed.ts +10 -10
  42. package/dist/templates/db-sql/src/KnexConnection.ts +74 -74
  43. package/dist/templates/db-sql/src/d.types.ts +18 -18
  44. package/dist/templates/db-sql/src/dao/sundays-package-version/sundays-package-version.dao.ts +71 -71
  45. package/dist/templates/db-sql/src/index.ts +9 -9
  46. package/dist/templates/db-sql/src/interfaces/sundays-package-version/sundays-package-version.interfaces.ts +6 -6
  47. package/dist/templates/db-sql/tsconfig.json +16 -16
  48. package/dist/templates/module/CLAUDE.md +158 -158
  49. package/dist/templates/module/tsconfig.json +19 -19
  50. package/package.json +1 -1
@@ -1,57 +1,57 @@
1
- import { Router } from 'express';
2
- import fs from 'fs';
3
- import path from 'path';
4
-
5
- export class IndexRouter {
6
- private _router: Router;
7
-
8
- constructor() {
9
- this._router = Router();
10
- this.loadRoutes();
11
- }
12
-
13
- private loadRoutes(): void {
14
- const routesPath = path.join(__dirname);
15
-
16
- const folders = fs.readdirSync(routesPath).filter(file =>
17
- fs.statSync(path.join(routesPath, file)).isDirectory()
18
- );
19
-
20
- folders.forEach(folder => {
21
- const baseName = `${folder}.router`;
22
- const tsPath = path.join(routesPath, folder, `${baseName}.ts`);
23
- const jsPath = path.join(routesPath, folder, `${baseName}.js`);
24
-
25
- let filePath = '';
26
- if (fs.existsSync(tsPath)) {
27
- filePath = tsPath;
28
- } else if (fs.existsSync(jsPath)) {
29
- filePath = jsPath;
30
- } else {
31
- console.warn(`[⚠] No route file found for: ${folder}`);
32
- return;
33
- }
34
-
35
- try {
36
- const routeModule = require(filePath);
37
- const RouterClass =
38
- routeModule.default || Object.values(routeModule).find((e) => typeof e === 'function');
39
-
40
- if (RouterClass) {
41
- const instance = new (RouterClass as any)();
42
- this._router.use(`/${folder}`, instance.router);
43
- console.log(`[✔] Route mounted: /${folder} → ${path.basename(filePath)}`);
44
- } else {
45
- console.warn(`[⚠] No class exported in: ${filePath}`);
46
- }
47
- } catch (err) {
48
- console.error(`[❌] Failed to load router at: ${filePath}`);
49
- console.error(err);
50
- }
51
- });
52
- }
53
-
54
- public get router(): Router {
55
- return this._router;
56
- }
57
- }
1
+ import { Router } from 'express';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+
5
+ export class IndexRouter {
6
+ private _router: Router;
7
+
8
+ constructor() {
9
+ this._router = Router();
10
+ this.loadRoutes();
11
+ }
12
+
13
+ private loadRoutes(): void {
14
+ const routesPath = path.join(__dirname);
15
+
16
+ const folders = fs.readdirSync(routesPath).filter(file =>
17
+ fs.statSync(path.join(routesPath, file)).isDirectory()
18
+ );
19
+
20
+ folders.forEach(folder => {
21
+ const baseName = `${folder}.router`;
22
+ const tsPath = path.join(routesPath, folder, `${baseName}.ts`);
23
+ const jsPath = path.join(routesPath, folder, `${baseName}.js`);
24
+
25
+ let filePath = '';
26
+ if (fs.existsSync(tsPath)) {
27
+ filePath = tsPath;
28
+ } else if (fs.existsSync(jsPath)) {
29
+ filePath = jsPath;
30
+ } else {
31
+ console.warn(`[⚠] No route file found for: ${folder}`);
32
+ return;
33
+ }
34
+
35
+ try {
36
+ const routeModule = require(filePath);
37
+ const RouterClass =
38
+ routeModule.default || Object.values(routeModule).find((e) => typeof e === 'function');
39
+
40
+ if (RouterClass) {
41
+ const instance = new (RouterClass as any)();
42
+ this._router.use(`/${folder}`, instance.router);
43
+ console.log(`[✔] Route mounted: /${folder} → ${path.basename(filePath)}`);
44
+ } else {
45
+ console.warn(`[⚠] No class exported in: ${filePath}`);
46
+ }
47
+ } catch (err) {
48
+ console.error(`[❌] Failed to load router at: ${filePath}`);
49
+ console.error(err);
50
+ }
51
+ });
52
+ }
53
+
54
+ public get router(): Router {
55
+ return this._router;
56
+ }
57
+ }
@@ -1,18 +1,18 @@
1
- import dotenv from 'dotenv';
2
- dotenv.config();
3
- import KnexManager from '../db/src/KnexConnection';
4
-
5
- const envPort: string = process.env.PORT || '3005';
6
-
7
- if (isNaN(parseInt(envPort))) {
8
- throw new Error('The port must to be a number');
9
- }
10
-
11
- const PORT: number = parseInt(envPort);
12
-
13
- (async () => {
14
- await KnexManager.connect();
15
- })().then(async () => {
16
- const { default: app } = await import('./app');
17
- app.listen(PORT, () => console.info(`Server up and running on port ${PORT}`));
18
- });
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+ import KnexManager from '../db/src/KnexConnection';
4
+
5
+ const envPort: string = process.env.PORT || '3005';
6
+
7
+ if (isNaN(parseInt(envPort))) {
8
+ throw new Error('The port must to be a number');
9
+ }
10
+
11
+ const PORT: number = parseInt(envPort);
12
+
13
+ (async () => {
14
+ await KnexManager.connect();
15
+ })().then(async () => {
16
+ const { default: app } = await import('./app');
17
+ app.listen(PORT, () => console.info(`Server up and running on port ${PORT}`));
18
+ });
@@ -1,10 +1,10 @@
1
- import { Request, Response, NextFunction } from 'express';
2
-
3
- export interface IBaseController {
4
- getAll(req: Request, res: Response, next: NextFunction): Promise<void>;
5
- getByUuid(req: Request, res: Response, next: NextFunction): Promise<void>;
6
- create(req: Request, res: Response, next: NextFunction): Promise<void>;
7
- update(req: Request, res: Response, next: NextFunction): Promise<void>;
8
- patch(req: Request, res: Response, next: NextFunction): Promise<void>;
9
- delete(req: Request, res: Response, next: NextFunction): Promise<void>;
10
- }
1
+ import { Request, Response, NextFunction } from 'express';
2
+
3
+ export interface IBaseController {
4
+ getAll(req: Request, res: Response, next: NextFunction): Promise<void>;
5
+ getByUuid(req: Request, res: Response, next: NextFunction): Promise<void>;
6
+ create(req: Request, res: Response, next: NextFunction): Promise<void>;
7
+ update(req: Request, res: Response, next: NextFunction): Promise<void>;
8
+ patch(req: Request, res: Response, next: NextFunction): Promise<void>;
9
+ delete(req: Request, res: Response, next: NextFunction): Promise<void>;
10
+ }
@@ -1,33 +1,33 @@
1
- import type { Knex } from "knex";
2
- import dotenv from "dotenv";
3
- dotenv.config();
4
-
5
- const isLocalhost = process.env.SQL_HOST === 'localhost' || process.env.SQL_HOST === '127.0.0.1';
6
- const rejectUnauthorized = process.env.SQL_REJECT_UNAUTHORIZED !== 'false';
7
-
8
- const sharedConfig: Knex.Config = {
9
- client: "postgresql",
10
- connection: {
11
- database: process.env.SQL_DB_NAME,
12
- user: process.env.SQL_USER,
13
- password: process.env.SQL_PASSWORD,
14
- host: process.env.SQL_HOST,
15
- port: process.env.SQL_PORT ? +process.env.SQL_PORT : 5432,
16
- ssl: isLocalhost ? false : { rejectUnauthorized },
17
- },
18
- pool: {
19
- min: 2,
20
- max: 10,
21
- },
22
- migrations: {
23
- tableName: "knex_migrations",
24
- },
25
- };
26
-
27
- const config: { [key: string]: Knex.Config } = {
28
- development: sharedConfig,
29
- staging: sharedConfig,
30
- production: sharedConfig,
31
- };
32
-
33
- export default config;
1
+ import type { Knex } from "knex";
2
+ import dotenv from "dotenv";
3
+ dotenv.config();
4
+
5
+ const isLocalhost = process.env.SQL_HOST === 'localhost' || process.env.SQL_HOST === '127.0.0.1';
6
+ const rejectUnauthorized = process.env.SQL_REJECT_UNAUTHORIZED !== 'false';
7
+
8
+ const sharedConfig: Knex.Config = {
9
+ client: "postgresql",
10
+ connection: {
11
+ database: process.env.SQL_DB_NAME,
12
+ user: process.env.SQL_USER,
13
+ password: process.env.SQL_PASSWORD,
14
+ host: process.env.SQL_HOST,
15
+ port: process.env.SQL_PORT ? +process.env.SQL_PORT : 5432,
16
+ ssl: isLocalhost ? false : { rejectUnauthorized },
17
+ },
18
+ pool: {
19
+ min: 2,
20
+ max: 10,
21
+ },
22
+ migrations: {
23
+ tableName: "knex_migrations",
24
+ },
25
+ };
26
+
27
+ const config: { [key: string]: Knex.Config } = {
28
+ development: sharedConfig,
29
+ staging: sharedConfig,
30
+ production: sharedConfig,
31
+ };
32
+
33
+ export default config;
@@ -1,13 +1,13 @@
1
- import type { Knex } from "knex";
2
-
3
- export async function up(knex: Knex): Promise<void> {
4
- await knex.schema.createTable("sundays_package_version", (table) => {
5
- table.increments("id").primary();
6
- table.string("versionName").notNullable();
7
- table.timestamps(true, true); // created_at, updated_at
8
- });
9
- }
10
-
11
- export async function down(knex: Knex): Promise<void> {
12
- await knex.schema.dropTableIfExists("sundays_package_version");
1
+ import type { Knex } from "knex";
2
+
3
+ export async function up(knex: Knex): Promise<void> {
4
+ await knex.schema.createTable("sundays_package_version", (table) => {
5
+ table.increments("id").primary();
6
+ table.string("versionName").notNullable();
7
+ table.timestamps(true, true); // created_at, updated_at
8
+ });
9
+ }
10
+
11
+ export async function down(knex: Knex): Promise<void> {
12
+ await knex.schema.dropTableIfExists("sundays_package_version");
13
13
  }
@@ -1,11 +1,11 @@
1
- import { Knex } from "knex";
2
-
3
- export async function seed(knex: Knex): Promise<void> {
4
- // Deletes ALL existing entries
5
- await knex("sundays_package_version").del();
6
-
7
- // Inserts seed entries
8
- await knex("sundays_package_version").insert([
9
- { versionName: "1.0.0" }
10
- ]);
1
+ import { Knex } from "knex";
2
+
3
+ export async function seed(knex: Knex): Promise<void> {
4
+ // Deletes ALL existing entries
5
+ await knex("sundays_package_version").del();
6
+
7
+ // Inserts seed entries
8
+ await knex("sundays_package_version").insert([
9
+ { versionName: "1.0.0" }
10
+ ]);
11
11
  }
@@ -1,74 +1,74 @@
1
- import { knex, Knex } from 'knex';
2
-
3
- class KnexManager {
4
- private static knexInstance: Knex<any, unknown[]> | null = null;
5
-
6
- /**
7
- * Open a new connection. Reuse the already existing one if there's any.
8
- */
9
- static async connect(
10
- config?: Knex.Config,
11
- connections?: number
12
- ): Promise<Knex<any, unknown[]>> {
13
- if (!KnexManager.knexInstance) {
14
- const isLocalhost = process.env.SQL_HOST === 'localhost' || process.env.SQL_HOST === '127.0.0.1';
15
- const rejectUnauthorized = process.env.SQL_REJECT_UNAUTHORIZED !== 'false';
16
- const defaultConfig = {
17
- client: 'pg',
18
- connection: {
19
- host: process.env.SQL_HOST,
20
- user: process.env.SQL_USER,
21
- password: process.env.SQL_PASSWORD,
22
- database: process.env.SQL_DB_NAME,
23
- port: Number(process.env.SQL_PORT) || 5432,
24
- ssl: isLocalhost ? false : { rejectUnauthorized },
25
- },
26
- pool: {
27
- min: 1,
28
- max: connections || 15,
29
- idleTimeoutMillis: 20000,
30
- acquireTimeoutMillis: 30000,
31
- },
32
- migrations: {
33
- tableName: 'knex_migrations',
34
- },
35
- };
36
- KnexManager.knexInstance = knex(config || defaultConfig);
37
- try {
38
- await KnexManager.knexInstance.raw('SELECT 1');
39
- console.info(`Knex connection established`);
40
- } catch (error) {
41
- console.error(`Failed to establish Knex connection:`, error);
42
- KnexManager.knexInstance = null;
43
- throw error;
44
- }
45
- }
46
-
47
- return KnexManager.knexInstance;
48
- }
49
-
50
- /**
51
- * Returns the active connection.
52
- */
53
- static getConnection(): Knex<any, unknown[]> {
54
- if (!KnexManager.knexInstance) {
55
- throw new Error(
56
- 'Knex connection has not been established. Call connect() first.'
57
- );
58
- }
59
- return KnexManager.knexInstance;
60
- }
61
-
62
- /**
63
- * Closes the connection and destroys the instance.
64
- */
65
- static async disconnect(): Promise<void> {
66
- if (KnexManager.knexInstance) {
67
- await KnexManager.knexInstance.destroy();
68
- KnexManager.knexInstance = null;
69
- console.info(`Knex connection closed`);
70
- }
71
- }
72
- }
73
-
74
- export default KnexManager;
1
+ import { knex, Knex } from 'knex';
2
+
3
+ class KnexManager {
4
+ private static knexInstance: Knex<any, unknown[]> | null = null;
5
+
6
+ /**
7
+ * Open a new connection. Reuse the already existing one if there's any.
8
+ */
9
+ static async connect(
10
+ config?: Knex.Config,
11
+ connections?: number
12
+ ): Promise<Knex<any, unknown[]>> {
13
+ if (!KnexManager.knexInstance) {
14
+ const isLocalhost = process.env.SQL_HOST === 'localhost' || process.env.SQL_HOST === '127.0.0.1';
15
+ const rejectUnauthorized = process.env.SQL_REJECT_UNAUTHORIZED !== 'false';
16
+ const defaultConfig = {
17
+ client: 'pg',
18
+ connection: {
19
+ host: process.env.SQL_HOST,
20
+ user: process.env.SQL_USER,
21
+ password: process.env.SQL_PASSWORD,
22
+ database: process.env.SQL_DB_NAME,
23
+ port: Number(process.env.SQL_PORT) || 5432,
24
+ ssl: isLocalhost ? false : { rejectUnauthorized },
25
+ },
26
+ pool: {
27
+ min: 1,
28
+ max: connections || 15,
29
+ idleTimeoutMillis: 20000,
30
+ acquireTimeoutMillis: 30000,
31
+ },
32
+ migrations: {
33
+ tableName: 'knex_migrations',
34
+ },
35
+ };
36
+ KnexManager.knexInstance = knex(config || defaultConfig);
37
+ try {
38
+ await KnexManager.knexInstance.raw('SELECT 1');
39
+ console.info(`Knex connection established`);
40
+ } catch (error) {
41
+ console.error(`Failed to establish Knex connection:`, error);
42
+ KnexManager.knexInstance = null;
43
+ throw error;
44
+ }
45
+ }
46
+
47
+ return KnexManager.knexInstance;
48
+ }
49
+
50
+ /**
51
+ * Returns the active connection.
52
+ */
53
+ static getConnection(): Knex<any, unknown[]> {
54
+ if (!KnexManager.knexInstance) {
55
+ throw new Error(
56
+ 'Knex connection has not been established. Call connect() first.'
57
+ );
58
+ }
59
+ return KnexManager.knexInstance;
60
+ }
61
+
62
+ /**
63
+ * Closes the connection and destroys the instance.
64
+ */
65
+ static async disconnect(): Promise<void> {
66
+ if (KnexManager.knexInstance) {
67
+ await KnexManager.knexInstance.destroy();
68
+ KnexManager.knexInstance = null;
69
+ console.info(`Knex connection closed`);
70
+ }
71
+ }
72
+ }
73
+
74
+ export default KnexManager;
@@ -1,18 +1,18 @@
1
- export interface IBaseDAO<T> {
2
- create(item: T): Promise<T>;
3
- getById(id: number): Promise<T | null>;
4
- getByUuid(uuid: string): Promise<T | null>;
5
- update(id: number, item: Partial<T>): Promise<T | null>;
6
- delete(id: number): Promise<boolean>;
7
- getAll(page: number, limit: number): Promise<IDataPaginator<T>>;
8
- }
9
-
10
- export interface IDataPaginator<T> {
11
- success: boolean;
12
- data: T[];
13
- page: number;
14
- limit: number;
15
- count: number;
16
- totalCount: number;
17
- totalPages: number;
18
- }
1
+ export interface IBaseDAO<T> {
2
+ create(item: T): Promise<T>;
3
+ getById(id: number): Promise<T | null>;
4
+ getByUuid(uuid: string): Promise<T | null>;
5
+ update(id: number, item: Partial<T>): Promise<T | null>;
6
+ delete(id: number): Promise<boolean>;
7
+ getAll(page: number, limit: number): Promise<IDataPaginator<T>>;
8
+ }
9
+
10
+ export interface IDataPaginator<T> {
11
+ success: boolean;
12
+ data: T[];
13
+ page: number;
14
+ limit: number;
15
+ count: number;
16
+ totalCount: number;
17
+ totalPages: number;
18
+ }
@@ -1,71 +1,71 @@
1
- import { Knex } from "knex";
2
- import { IBaseDAO, IDataPaginator } from "../../d.types";
3
- import { ISundaysPackageVersion } from "../../interfaces/sundays-package-version/sundays-package-version.interfaces";
4
- import KnexManager from "../../KnexConnection";
5
-
6
- export class SundaysPackageVersionDAO implements IBaseDAO<ISundaysPackageVersion> {
7
- private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
8
-
9
- async create(item: ISundaysPackageVersion): Promise<ISundaysPackageVersion> {
10
- const [created] = await this._knex("sundays_package_version").insert(item).returning("*");
11
- return created;
12
- }
13
-
14
- async getById(id: number): Promise<ISundaysPackageVersion | null> {
15
- const result = await this._knex("sundays_package_version")
16
- .select("*")
17
- .where("id", id)
18
- .first();
19
- return result || null;
20
- }
21
-
22
- async getByUuid(uuid: string): Promise<ISundaysPackageVersion | null> {
23
- const result = await this._knex("sundays_package_version")
24
- .select("*")
25
- .where("uuid", uuid)
26
- .first();
27
- return result || null;
28
- }
29
-
30
- async update(id: number, item: Partial<ISundaysPackageVersion>): Promise<ISundaysPackageVersion | null> {
31
- const [updated] = await this._knex("sundays_package_version")
32
- .where({ id })
33
- .update(item)
34
- .returning("*");
35
- return updated || null;
36
- }
37
-
38
- async delete(id: number): Promise<boolean> {
39
- const result = await this._knex("sundays_package_version").where({ id }).del();
40
- return result > 0;
41
- }
42
-
43
- async getAll(page: number, limit: number): Promise<IDataPaginator<ISundaysPackageVersion>> {
44
- const safeLimit = Math.max(limit, 1);
45
- const offset = (page - 1) * safeLimit;
46
-
47
- const query = this._knex("sundays_package_version").select("*");
48
-
49
- const [countResult] = await query.clone().clearSelect().count("* as count");
50
- const totalCount = +countResult.count;
51
- const data = await query.clone().limit(safeLimit).offset(offset).orderBy("id", "desc");
52
-
53
- return {
54
- success: true,
55
- data,
56
- page,
57
- limit: safeLimit,
58
- count: data.length,
59
- totalCount,
60
- totalPages: Math.ceil(totalCount / safeLimit),
61
- };
62
- }
63
-
64
- async getLatestVersion(): Promise<ISundaysPackageVersion | null> {
65
- const result = await this._knex("sundays_package_version")
66
- .select("*")
67
- .orderBy("id", "desc")
68
- .first();
69
- return result || null;
70
- }
71
- }
1
+ import { Knex } from "knex";
2
+ import { IBaseDAO, IDataPaginator } from "../../d.types";
3
+ import { ISundaysPackageVersion } from "../../interfaces/sundays-package-version/sundays-package-version.interfaces";
4
+ import KnexManager from "../../KnexConnection";
5
+
6
+ export class SundaysPackageVersionDAO implements IBaseDAO<ISundaysPackageVersion> {
7
+ private _knex: Knex<any, unknown[]> = KnexManager.getConnection();
8
+
9
+ async create(item: ISundaysPackageVersion): Promise<ISundaysPackageVersion> {
10
+ const [created] = await this._knex("sundays_package_version").insert(item).returning("*");
11
+ return created;
12
+ }
13
+
14
+ async getById(id: number): Promise<ISundaysPackageVersion | null> {
15
+ const result = await this._knex("sundays_package_version")
16
+ .select("*")
17
+ .where("id", id)
18
+ .first();
19
+ return result || null;
20
+ }
21
+
22
+ async getByUuid(uuid: string): Promise<ISundaysPackageVersion | null> {
23
+ const result = await this._knex("sundays_package_version")
24
+ .select("*")
25
+ .where("uuid", uuid)
26
+ .first();
27
+ return result || null;
28
+ }
29
+
30
+ async update(id: number, item: Partial<ISundaysPackageVersion>): Promise<ISundaysPackageVersion | null> {
31
+ const [updated] = await this._knex("sundays_package_version")
32
+ .where({ id })
33
+ .update(item)
34
+ .returning("*");
35
+ return updated || null;
36
+ }
37
+
38
+ async delete(id: number): Promise<boolean> {
39
+ const result = await this._knex("sundays_package_version").where({ id }).del();
40
+ return result > 0;
41
+ }
42
+
43
+ async getAll(page: number, limit: number): Promise<IDataPaginator<ISundaysPackageVersion>> {
44
+ const safeLimit = Math.max(limit, 1);
45
+ const offset = (page - 1) * safeLimit;
46
+
47
+ const query = this._knex("sundays_package_version").select("*");
48
+
49
+ const [countResult] = await query.clone().clearSelect().count("* as count");
50
+ const totalCount = +countResult.count;
51
+ const data = await query.clone().limit(safeLimit).offset(offset).orderBy("id", "desc");
52
+
53
+ return {
54
+ success: true,
55
+ data,
56
+ page,
57
+ limit: safeLimit,
58
+ count: data.length,
59
+ totalCount,
60
+ totalPages: Math.ceil(totalCount / safeLimit),
61
+ };
62
+ }
63
+
64
+ async getLatestVersion(): Promise<ISundaysPackageVersion | null> {
65
+ const result = await this._knex("sundays_package_version")
66
+ .select("*")
67
+ .orderBy("id", "desc")
68
+ .first();
69
+ return result || null;
70
+ }
71
+ }
@@ -1,9 +1,9 @@
1
- // DAOs
2
- export { SundaysPackageVersionDAO } from "./dao/sundays-package-version/sundays-package-version.dao";
3
-
4
- // Interfaces
5
- export { IDataPaginator } from "./d.types";
6
- export { ISundaysPackageVersion } from "./interfaces/sundays-package-version/sundays-package-version.interfaces";
7
-
8
- import KnexManager from './KnexConnection';
9
- export { KnexManager };
1
+ // DAOs
2
+ export { SundaysPackageVersionDAO } from "./dao/sundays-package-version/sundays-package-version.dao";
3
+
4
+ // Interfaces
5
+ export { IDataPaginator } from "./d.types";
6
+ export { ISundaysPackageVersion } from "./interfaces/sundays-package-version/sundays-package-version.interfaces";
7
+
8
+ import KnexManager from './KnexConnection';
9
+ export { KnexManager };
@@ -1,6 +1,6 @@
1
- export interface ISundaysPackageVersion {
2
- id: number;
3
- versionName: string;
4
- createdAt: string;
5
- updatedAt: string;
6
- }
1
+ export interface ISundaysPackageVersion {
2
+ id: number;
3
+ versionName: string;
4
+ createdAt: string;
5
+ updatedAt: string;
6
+ }