0.1.2 • Published 3 months ago

@softkit/typeorm-service v0.1.2

Weekly downloads
-
License
-
Repository
-
Last release
3 months ago

Typeorm Service Library

This library has some useful utilities for @softkit/typeorm library, that expose useful base services to use in your application.

This library is also throwing standard exceptions from @softkit/exceptions library. So interceptors can handle everything properly.

Installation

yarn add @softkit/typeorm-service

Examples:

  • BaseEntityService - it has basic methods for creating, finding, updating, archiving, deleting entities. Simple CRUD based operations, and you can also extend it with your own methods.
import { Injectable } from '@nestjs/common';
import { Transactional } from 'typeorm-transactional';
import { CustomUserRoleRepository } from '../../repositories';
import { BaseEntityService } from '@softkit/typeorm-service';
import { IsNull } from 'typeorm';

@Injectable()
export class CustomUserRoleService extends BaseEntityService<CustomUserRole, CustomUserRoleRepository> {
  constructor(repository: CustomUserRoleRepository) {
    super(repository);
  }

  @Transactional()
  async findDefaultRole() {
    return await this.repository.findOne({
      where: {
        roleType: RoleType.REGULAR_USER,
        tenantId: IsNull(),
      },
    });
  }
}
  • BaseTenantEntityService - it has basic methods for creating, finding, updating, archiving, deleting tenant base entities. Simple CRUD based operations, and you can also extend it with your own methods.
@Injectable()
export class CustomUserRoleTenantService extends BaseTenantEntityService<CustomUserRole, CustomUserRoleTenantRepository> {
  constructor(repository: CustomUserRoleTenantRepository) {
    super(repository);
  }
}

Tip:

Each of these services has additional parameter in generics, after repository type, that is used for excluding auto generated types, to keep service type safe and do not annoy you with type errors.

Example (This will exclude 5 fields from base methods and types, because it will be populated by subscribers):

@Injectable()
export class CustomUserRoleTenantService extends BaseTenantEntityService<CustomUserRole, CustomUserRoleTenantRepository, Pick<CustomUserRole, 'id' | 'createdAt' | 'updatedAt' | 'deletedAt' | 'userId'>> {
  constructor(repository: CustomUserRoleTenantRepository) {
    super(repository);
  }
}
0.1.2

3 months ago

0.1.1

3 months ago

0.1.0

3 months ago

0.0.13

5 months ago

0.0.12

5 months ago

0.0.11

5 months ago

0.0.10

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago