yegara 1.0.26 → 1.0.28

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 (47) hide show
  1. package/package.json +4 -1
  2. package/src/db/typeorm/audit.entity.ts +13 -13
  3. package/src/db/typeorm/index.ts +2 -2
  4. package/src/db/typeorm/typeorm.config.ts +31 -31
  5. package/src/db/typeorm/typeorm.service.ts +18 -18
  6. package/src/dtos/language.dto.ts +19 -19
  7. package/src/generics/drizzle/controllers/extra-crud.controller.ts +62 -62
  8. package/src/generics/drizzle/controllers/index.ts +1 -1
  9. package/src/generics/drizzle/controllers/relation-crud.controller.ts +39 -39
  10. package/src/generics/drizzle/controllers/schema-crud.controller.ts +60 -60
  11. package/src/generics/drizzle/index.ts +1 -1
  12. package/src/generics/drizzle/services/extra-crud.service.ts +43 -43
  13. package/src/generics/drizzle/services/index.ts +1 -1
  14. package/src/generics/drizzle/services/relation-crud.service.ts +96 -96
  15. package/src/generics/drizzle/services/schema-crud.service.ts +38 -38
  16. package/src/generics/dtos/relation-crud.dto.ts +23 -23
  17. package/src/generics/email/email.config.ts +34 -34
  18. package/src/generics/email/email.service.ts +43 -43
  19. package/src/generics/email/index.ts +1 -1
  20. package/src/generics/exceptions/global-filter-exceptions.ts +42 -42
  21. package/src/generics/index.ts +5 -5
  22. package/src/generics/schemas/audit.schema.ts +6 -6
  23. package/src/generics/typeorm/controllers/dto/validate.dto.ts +11 -11
  24. package/src/generics/typeorm/controllers/entity-crud.controller.ts +64 -63
  25. package/src/generics/typeorm/controllers/extra-crud.controller.ts +68 -66
  26. package/src/generics/typeorm/controllers/index.ts +2 -2
  27. package/src/generics/typeorm/controllers/relation-crud.controller.ts +61 -59
  28. package/src/generics/typeorm/index.ts +1 -1
  29. package/src/generics/typeorm/services/entity-crud.service.ts +38 -38
  30. package/src/generics/typeorm/services/extra-crud.service.ts +44 -44
  31. package/src/generics/typeorm/services/index.ts +2 -2
  32. package/src/generics/typeorm/services/relation-crud.service.ts +123 -123
  33. package/src/index.ts +4 -4
  34. package/src/modules/auth/auth.module.ts +36 -36
  35. package/src/modules/auth/decorators/current-user.decorator.ts +7 -7
  36. package/src/modules/auth/decorators/index.ts +1 -1
  37. package/src/modules/auth/decorators/public.decorator.ts +4 -4
  38. package/src/modules/auth/guards/index.ts +1 -1
  39. package/src/modules/auth/guards/jwt-refresh.guard.ts +4 -4
  40. package/src/modules/auth/guards/jwt.guard.ts +44 -44
  41. package/src/modules/auth/index.ts +3 -3
  42. package/src/modules/auth/services/auth.helper.ts +155 -155
  43. package/src/modules/auth/services/index.ts +2 -2
  44. package/src/modules/auth/services/jwt-refresh-strategy.service.ts +20 -20
  45. package/src/modules/auth/services/jwt-strategy.service.ts +17 -17
  46. package/src/yegara.module.ts +11 -11
  47. package/tsconfig.json +26 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yegara",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "exports": {
@@ -17,14 +17,17 @@
17
17
  "dependencies": {
18
18
  "@nestjs-modules/mailer": "^2.0.2",
19
19
  "@nestjs/common": "^10.0.0",
20
+ "@nestjs/config": "^4.0.2",
20
21
  "@nestjs/core": "^10.0.0",
21
22
  "@nestjs/jwt": "10.2.0",
22
23
  "@nestjs/passport": "^10.0.3",
23
24
  "@nestjs/platform-express": "^10.0.0",
24
25
  "@nestjs/swagger": "^8.1.0",
25
26
  "@types/passport-jwt": "^4.0.1",
27
+ "bcrypt": "^6.0.0",
26
28
  "class-transformer": "^0.5.1",
27
29
  "class-validator": "^0.14.1",
30
+ "dotenv": "^17.2.3",
28
31
  "drizzle-orm": "^0.36.4",
29
32
  "express": "^4.21.2",
30
33
  "passport-jwt": "^4.0.1",
@@ -1,13 +1,13 @@
1
- import { CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Entity } from "typeorm";
2
-
3
- @Entity()
4
- export class Audit {
5
- @CreateDateColumn({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6
- createdAt: Date;
7
-
8
- @UpdateDateColumn({ type: "timestamp", nullable: true })
9
- updatedAt: Date;
10
-
11
- @DeleteDateColumn({ type: "timestamp", nullable: true })
12
- deletedAt: Date;
13
- }
1
+ import { CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Entity } from "typeorm";
2
+
3
+ @Entity()
4
+ export class Audit {
5
+ @CreateDateColumn({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
6
+ createdAt?: Date;
7
+
8
+ @UpdateDateColumn({ type: "timestamp", nullable: true })
9
+ updatedAt?: Date;
10
+
11
+ @DeleteDateColumn({ type: "timestamp", nullable: true })
12
+ deletedAt?: Date;
13
+ }
@@ -1,3 +1,3 @@
1
- export * from './typeorm.config'
2
- export * from './typeorm.service'
1
+ export * from './typeorm.config'
2
+ export * from './typeorm.service'
3
3
  export * from './audit.entity'
@@ -1,31 +1,31 @@
1
- import * as dotenv from 'dotenv'
2
- import { DataSource, DataSourceOptions } from 'typeorm';
3
- import { SeederOptions } from 'typeorm-extension';
4
- dotenv.config({ path: '.env' });
5
-
6
-
7
- const pathPrefix = '';
8
-
9
- export const typeormConfig = {
10
- type: 'postgres',
11
- host: process.env.DATABASE_HOST,
12
- port: Number(process.env.DATABASE_PORT),
13
- database: process.env.DATABASE_NAME,
14
- username: process.env.DATABASE_USER,
15
- password: process.env.DATABASE_PASSWORD,
16
- schema: process.env.DATABASE_SCHEMA,
17
- entities: [`${pathPrefix}dist/db/entities/**/*.entity.{ts,js}`],
18
- migrations: [`${pathPrefix}dist/db/migrations/*.{ts,js}`],
19
- subscribers: [`${pathPrefix}dist/db/subscribers/*.{ts,js}`],
20
- migrationsRun: true,
21
- seeds: [`${pathPrefix}dist/db/seeders/**.seeder.{ts,js}`],
22
- migrationsTableName: 'typeorm_migrations',
23
- logger: 'advanced-console',
24
- logging: 'all',
25
- synchronize: false,
26
- autoLoadEntities: true,
27
- } as DataSourceOptions & SeederOptions;
28
-
29
- const dataSource = new DataSource(typeormConfig);
30
-
31
- export default dataSource;
1
+ import * as dotenv from 'dotenv'
2
+ import { DataSource, DataSourceOptions } from 'typeorm';
3
+ import { SeederOptions } from 'typeorm-extension';
4
+ dotenv.config({ path: '.env' });
5
+
6
+
7
+ const pathPrefix = '';
8
+
9
+ export const typeormConfig = {
10
+ type: 'postgres',
11
+ host: process.env.DATABASE_HOST,
12
+ port: Number(process.env.DATABASE_PORT),
13
+ database: process.env.DATABASE_NAME,
14
+ username: process.env.DATABASE_USER,
15
+ password: process.env.DATABASE_PASSWORD,
16
+ schema: process.env.DATABASE_SCHEMA,
17
+ entities: [`${pathPrefix}dist/db/entities/**/*.entity.{ts,js}`],
18
+ migrations: [`${pathPrefix}dist/db/migrations/*.{ts,js}`],
19
+ subscribers: [`${pathPrefix}dist/db/subscribers/*.{ts,js}`],
20
+ migrationsRun: true,
21
+ seeds: [`${pathPrefix}dist/db/seeders/**.seeder.{ts,js}`],
22
+ migrationsTableName: 'typeorm_migrations',
23
+ logger: 'advanced-console',
24
+ logging: 'all',
25
+ synchronize: false,
26
+ autoLoadEntities: true,
27
+ } as DataSourceOptions & SeederOptions;
28
+
29
+ const dataSource = new DataSource(typeormConfig);
30
+
31
+ export default dataSource;
@@ -1,18 +1,18 @@
1
- import { Injectable } from "@nestjs/common";
2
- import { TypeOrmDataSourceFactory, TypeOrmModuleOptions, TypeOrmOptionsFactory } from "@nestjs/typeorm";
3
- import { typeormConfig } from "./typeorm.config";
4
- import { SeederOptions } from "typeorm-extension";
5
-
6
- @Injectable()
7
- export class TypeOrmService implements TypeOrmOptionsFactory {
8
- public createTypeOrmOptions(): TypeOrmModuleOptions & SeederOptions {
9
- return typeormConfig;
10
- }
11
- }
12
-
13
- @Injectable()
14
- export class TypeOrmConfigService implements TypeOrmOptionsFactory {
15
- public createTypeOrmOptions(): TypeOrmModuleOptions & SeederOptions {
16
- return typeormConfig;
17
- }
18
- }
1
+ import { Injectable } from "@nestjs/common";
2
+ import { TypeOrmDataSourceFactory, TypeOrmModuleOptions, TypeOrmOptionsFactory } from "@nestjs/typeorm";
3
+ import { typeormConfig } from "./typeorm.config";
4
+ import { SeederOptions } from "typeorm-extension";
5
+
6
+ @Injectable()
7
+ export class TypeOrmService implements TypeOrmOptionsFactory {
8
+ public createTypeOrmOptions(): TypeOrmModuleOptions & SeederOptions {
9
+ return typeormConfig;
10
+ }
11
+ }
12
+
13
+ @Injectable()
14
+ export class TypeOrmConfigService implements TypeOrmOptionsFactory {
15
+ public createTypeOrmOptions(): TypeOrmModuleOptions & SeederOptions {
16
+ return typeormConfig;
17
+ }
18
+ }
@@ -1,20 +1,20 @@
1
- import { ApiProperty } from "@nestjs/swagger";
2
- import { IsNotEmpty, IsString } from "class-validator";
3
-
4
- export class LanguageDto {
5
- @ApiProperty({
6
- description: 'The language name',
7
- example: 'English',
8
- })
9
- @IsNotEmpty()
10
- @IsString()
11
- en!: string;
12
-
13
- @ApiProperty({
14
- description: 'The language name in the native language',
15
- example: 'አማርኛ',
16
- })
17
- @IsNotEmpty()
18
- @IsString()
19
- am!: string;
1
+ import { ApiProperty } from "@nestjs/swagger";
2
+ import { IsNotEmpty, IsString } from "class-validator";
3
+
4
+ export class LanguageDto {
5
+ @ApiProperty({
6
+ description: 'The language name',
7
+ example: 'English',
8
+ })
9
+ @IsNotEmpty()
10
+ @IsString()
11
+ en!: string;
12
+
13
+ @ApiProperty({
14
+ description: 'The language name in the native language',
15
+ example: 'አማርኛ',
16
+ })
17
+ @IsNotEmpty()
18
+ @IsString()
19
+ am!: string;
20
20
  }
@@ -1,62 +1,62 @@
1
- import { Body, Controller, Delete, Get, Param, Post, Put, UseInterceptors } from "@nestjs/common";
2
- import { ApiBearerAuth, ApiBody } from "@nestjs/swagger";
3
- import { DExtraCrudService } from "../services/extra-crud.service";
4
-
5
- export type ExtraCrudOptions = {
6
- createDto?: { new(): NonNullable<unknown> };
7
- updateDto?: { new(): NonNullable<unknown> };
8
- };
9
-
10
-
11
- export function DExtraCrudController(
12
- options?: ExtraCrudOptions,
13
- ) {
14
- @Controller()
15
- @UseInterceptors(/* your interceptors if any */)
16
- @ApiBearerAuth()
17
- class ExtraCrudControllerHost {
18
- constructor(
19
- public readonly schemaCrudService: DExtraCrudService,
20
- ) {
21
- }
22
-
23
- @Get('/list/:parentId')
24
- async findAll(
25
- @Param('parentId') parentId: string
26
- ) {
27
- return await this.schemaCrudService.findAll(parentId)
28
- }
29
-
30
- @Get('/:id')
31
- async findOne(
32
- @Param('id') id: string
33
- ) {
34
- return await this.schemaCrudService.findOne(id)
35
- }
36
-
37
- @Post()
38
- @ApiBody({ type: options?.createDto })
39
- async create(
40
- @Body() itemData: any
41
- ) {
42
- return await this.schemaCrudService.create(itemData)
43
- }
44
-
45
- @Put('/:id')
46
- @ApiBody({ type: options?.updateDto })
47
- async update(
48
- @Param('id') id: string,
49
- @Body() itemData: any
50
- ) {
51
- return await this.schemaCrudService.update(id, itemData)
52
- }
53
-
54
- @Delete('/:id')
55
- async delete(
56
- @Param('id') id: string
57
- ) {
58
- return await this.schemaCrudService.delete(id)
59
- }
60
- }
61
- return ExtraCrudControllerHost
62
- }
1
+ import { Body, Controller, Delete, Get, Param, Post, Put, UseInterceptors } from "@nestjs/common";
2
+ import { ApiBearerAuth, ApiBody } from "@nestjs/swagger";
3
+ import { DExtraCrudService } from "../services/extra-crud.service";
4
+
5
+ export type ExtraCrudOptions = {
6
+ createDto?: { new(): NonNullable<unknown> };
7
+ updateDto?: { new(): NonNullable<unknown> };
8
+ };
9
+
10
+
11
+ export function DExtraCrudController(
12
+ options?: ExtraCrudOptions,
13
+ ): any {
14
+ @Controller()
15
+ @UseInterceptors(/* your interceptors if any */)
16
+ @ApiBearerAuth()
17
+ class ExtraCrudControllerHost {
18
+ constructor(
19
+ public readonly schemaCrudService: DExtraCrudService,
20
+ ) {
21
+ }
22
+
23
+ @Get('/list/:parentId')
24
+ async findAll(
25
+ @Param('parentId') parentId: string
26
+ ) {
27
+ return await this.schemaCrudService.findAll(parentId)
28
+ }
29
+
30
+ @Get('/:id')
31
+ async findOne(
32
+ @Param('id') id: string
33
+ ) {
34
+ return await this.schemaCrudService.findOne(id)
35
+ }
36
+
37
+ @Post()
38
+ @ApiBody({ type: options?.createDto })
39
+ async create(
40
+ @Body() itemData: any
41
+ ) {
42
+ return await this.schemaCrudService.create(itemData)
43
+ }
44
+
45
+ @Put('/:id')
46
+ @ApiBody({ type: options?.updateDto })
47
+ async update(
48
+ @Param('id') id: string,
49
+ @Body() itemData: any
50
+ ) {
51
+ return await this.schemaCrudService.update(id, itemData)
52
+ }
53
+
54
+ @Delete('/:id')
55
+ async delete(
56
+ @Param('id') id: string
57
+ ) {
58
+ return await this.schemaCrudService.delete(id)
59
+ }
60
+ }
61
+ return ExtraCrudControllerHost
62
+ }
@@ -1,2 +1,2 @@
1
- export * from './extra-crud.controller'
1
+ export * from './extra-crud.controller'
2
2
  export * from './extra-crud.controller'
@@ -1,39 +1,39 @@
1
- import { Body, Controller, Get, Param, Post } from "@nestjs/common";
2
- import { DRelationCrudService } from "../services/relation-crud.service";
3
- import { AssignSecondForFirstDTO, AssignFirstForSecondDTO } from "../../dtos/relation-crud.dto";
4
-
5
- @Controller()
6
- export class DRelationCrudController {
7
- constructor(
8
- private readonly schemaCrudService: DRelationCrudService,
9
- ) {
10
- }
11
-
12
- @Get('/given-first/:id')
13
- async givenFirst(
14
- @Param('id') id: string
15
- ) {
16
- return await this.schemaCrudService.givenFirst(id)
17
- }
18
-
19
- @Get('/given-second/:id')
20
- async givenSecond(
21
- @Param('id') id: string
22
- ) {
23
- return await this.schemaCrudService.givenSecond(id)
24
- }
25
-
26
- @Post('assign-firsts-for-second')
27
- async assignSecond(
28
- @Body() itemData: AssignFirstForSecondDTO
29
- ) {
30
- return await this.schemaCrudService.assignFirstsForSecond(itemData.secondId, itemData.firstIds)
31
- }
32
-
33
- @Post('assign-seconds-for-first')
34
- async assignFirst(
35
- @Body() itemData: AssignSecondForFirstDTO
36
- ) {
37
- return await this.schemaCrudService.assignSecondsForFirst(itemData.firstId, itemData.secondIds)
38
- }
39
- }
1
+ import { Body, Controller, Get, Param, Post } from "@nestjs/common";
2
+ import { DRelationCrudService } from "../services/relation-crud.service";
3
+ import { AssignSecondForFirstDTO, AssignFirstForSecondDTO } from "../../dtos/relation-crud.dto";
4
+
5
+ @Controller()
6
+ export class DRelationCrudController {
7
+ constructor(
8
+ private readonly schemaCrudService: DRelationCrudService,
9
+ ) {
10
+ }
11
+
12
+ @Get('/given-first/:id')
13
+ async givenFirst(
14
+ @Param('id') id: string
15
+ ) {
16
+ return await this.schemaCrudService.givenFirst(id)
17
+ }
18
+
19
+ @Get('/given-second/:id')
20
+ async givenSecond(
21
+ @Param('id') id: string
22
+ ) {
23
+ return await this.schemaCrudService.givenSecond(id)
24
+ }
25
+
26
+ @Post('assign-firsts-for-second')
27
+ async assignSecond(
28
+ @Body() itemData: AssignFirstForSecondDTO
29
+ ) {
30
+ return await this.schemaCrudService.assignFirstsForSecond(itemData.secondId, itemData.firstIds)
31
+ }
32
+
33
+ @Post('assign-seconds-for-first')
34
+ async assignFirst(
35
+ @Body() itemData: AssignSecondForFirstDTO
36
+ ) {
37
+ return await this.schemaCrudService.assignSecondsForFirst(itemData.firstId, itemData.secondIds)
38
+ }
39
+ }
@@ -1,60 +1,60 @@
1
- import { Body, Controller, Delete, Get, Param, Post, Put, UseInterceptors } from "@nestjs/common";
2
- import { DSchemaCrudService } from "../services/schema-crud.service";
3
- import { ApiBearerAuth, ApiBody } from "@nestjs/swagger";
4
-
5
- export type SchemaCrudOptions = {
6
- createDto?: { new(): NonNullable<unknown> };
7
- updateDto?: { new(): NonNullable<unknown> };
8
- };
9
-
10
-
11
- export function DSchemaCrudController(
12
- options?: SchemaCrudOptions,
13
- ) {
14
- @Controller()
15
- @UseInterceptors(/* your interceptors if any */)
16
- @ApiBearerAuth()
17
- class SchemaCrudControllerHost {
18
- constructor(
19
- public readonly schemaCrudService: DSchemaCrudService,
20
- ) {
21
- }
22
-
23
- @Get()
24
- async findAll() {
25
- return await this.schemaCrudService.findAll()
26
- }
27
-
28
- @Get('/:id')
29
- async findOne(
30
- @Param('id') id: string
31
- ) {
32
- return await this.schemaCrudService.findOne(id)
33
- }
34
-
35
- @Post()
36
- @ApiBody({ type: options?.createDto })
37
- async create(
38
- @Body() itemData: any
39
- ) {
40
- return await this.schemaCrudService.create(itemData)
41
- }
42
-
43
- @Put('/:id')
44
- @ApiBody({ type: options?.updateDto })
45
- async update(
46
- @Param('id') id: string,
47
- @Body() itemData: any
48
- ) {
49
- return await this.schemaCrudService.update(id, itemData)
50
- }
51
-
52
- @Delete('/:id')
53
- async delete(
54
- @Param('id') id: string
55
- ) {
56
- return await this.schemaCrudService.delete(id)
57
- }
58
- }
59
- return SchemaCrudControllerHost
60
- }
1
+ import { Body, Controller, Delete, Get, Param, Post, Put, UseInterceptors } from "@nestjs/common";
2
+ import { DSchemaCrudService } from "../services/schema-crud.service";
3
+ import { ApiBearerAuth, ApiBody } from "@nestjs/swagger";
4
+
5
+ export type SchemaCrudOptions = {
6
+ createDto?: { new(): NonNullable<unknown> };
7
+ updateDto?: { new(): NonNullable<unknown> };
8
+ };
9
+
10
+
11
+ export function DSchemaCrudController(
12
+ options?: SchemaCrudOptions,
13
+ ): any {
14
+ @Controller()
15
+ @UseInterceptors(/* your interceptors if any */)
16
+ @ApiBearerAuth()
17
+ class SchemaCrudControllerHost {
18
+ constructor(
19
+ public readonly schemaCrudService: DSchemaCrudService,
20
+ ) {
21
+ }
22
+
23
+ @Get()
24
+ async findAll() {
25
+ return await this.schemaCrudService.findAll()
26
+ }
27
+
28
+ @Get('/:id')
29
+ async findOne(
30
+ @Param('id') id: string
31
+ ) {
32
+ return await this.schemaCrudService.findOne(id)
33
+ }
34
+
35
+ @Post()
36
+ @ApiBody({ type: options?.createDto })
37
+ async create(
38
+ @Body() itemData: any
39
+ ) {
40
+ return await this.schemaCrudService.create(itemData)
41
+ }
42
+
43
+ @Put('/:id')
44
+ @ApiBody({ type: options?.updateDto })
45
+ async update(
46
+ @Param('id') id: string,
47
+ @Body() itemData: any
48
+ ) {
49
+ return await this.schemaCrudService.update(id, itemData)
50
+ }
51
+
52
+ @Delete('/:id')
53
+ async delete(
54
+ @Param('id') id: string
55
+ ) {
56
+ return await this.schemaCrudService.delete(id)
57
+ }
58
+ }
59
+ return SchemaCrudControllerHost
60
+ }
@@ -1,2 +1,2 @@
1
- export * from './controllers'
1
+ export * from './controllers'
2
2
  export * from './services'
@@ -1,44 +1,44 @@
1
- import { Injectable } from "@nestjs/common";
2
- import { eq } from "drizzle-orm";
3
- import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
- import { PgTableWithColumns } from "drizzle-orm/pg-core";
5
-
6
- @Injectable()
7
- export class DExtraCrudService {
8
- constructor(
9
- protected readonly db: NodePgDatabase<any>,
10
- private readonly schema: PgTableWithColumns<any>,
11
- private readonly parentFieldName: string
12
- ) {
13
- }
14
-
15
- async findAll(parentFieldValue: string) {
16
- const data = await this.db.select()
17
- .from(this.schema)
18
- .where(eq(this.schema[this.parentFieldName], parentFieldValue))
19
-
20
- return {
21
- count: data.length,
22
- items: data
23
- }
24
-
25
- }
26
-
27
- async findOne(id: string) {
28
- return await this.db.select()
29
- .from(this.schema)
30
- .where(eq(this.schema.id, id));
31
- }
32
-
33
- async create(itemData: any) {
34
- return await this.db.insert(this.schema).values(itemData).returning();
35
- }
36
-
37
- async update(id: string, itemData: any) {
38
- return await this.db.update(this.schema).set(itemData).where(eq(this.schema.id, id));
39
- }
40
-
41
- async delete(id: string) {
42
- return await this.db.delete(this.schema).where(eq(this.schema.id, id));
43
- }
1
+ import { Injectable } from "@nestjs/common";
2
+ import { eq } from "drizzle-orm";
3
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
+ import { PgTableWithColumns } from "drizzle-orm/pg-core";
5
+
6
+ @Injectable()
7
+ export class DExtraCrudService {
8
+ constructor(
9
+ protected readonly db: NodePgDatabase<any>,
10
+ private readonly schema: PgTableWithColumns<any>,
11
+ private readonly parentFieldName: string
12
+ ) {
13
+ }
14
+
15
+ async findAll(parentFieldValue: string) {
16
+ const data = await this.db.select()
17
+ .from(this.schema)
18
+ .where(eq(this.schema[this.parentFieldName], parentFieldValue))
19
+
20
+ return {
21
+ count: data.length,
22
+ items: data
23
+ }
24
+
25
+ }
26
+
27
+ async findOne(id: string) {
28
+ return await this.db.select()
29
+ .from(this.schema)
30
+ .where(eq(this.schema.id, id));
31
+ }
32
+
33
+ async create(itemData: any) {
34
+ return await this.db.insert(this.schema).values(itemData).returning();
35
+ }
36
+
37
+ async update(id: string, itemData: any) {
38
+ return await this.db.update(this.schema).set(itemData).where(eq(this.schema.id, id));
39
+ }
40
+
41
+ async delete(id: string) {
42
+ return await this.db.delete(this.schema).where(eq(this.schema.id, id));
43
+ }
44
44
  }
@@ -1,2 +1,2 @@
1
- export * from './schema-crud.service'
1
+ export * from './schema-crud.service'
2
2
  export * from './extra-crud.service'