1.1.3 • Published 9 months ago

@adityadarma/adonis-service-repository v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Adonis Service Repository

gh-workflow-image npm-image npm-downloads license-image

Service repository is a pattern to separate business logic and query logic. This package is designed to help simplify the maintenance of large and medium scale applications.

Installation

node ace add @adityadarma/adonis-service-repository

Usage

*Service

Create service

node ace make:service ServiceName

Using Core or Base

If you want to change the core service according to your wishes without changing the existing methods, you can publish it first.

node ace service:publish

Used on controller

protected nameService: NameService;

construct(nameService: NameService)
{
    this.nameService = nameService;
}

async data()
{
    return this.nameService.functionName().getData();
}

async json()
{
  return this.nameService.functionName().toJson();
}

async withResource()
{
    return this.nameService.functionName().toJsonFromResource(ClassResource);
}

Use Service & Exception

Every all exception, must have handle to class CustomException

async nameMethod()
{
    try {
      .........
      if (false) {
        throw new CustomException('Error exception');
      }
      ..........
      return this.setData(data)
        .setMessage('Message data')
        .setCode(200);
      // OR
      return this.setData(data)
        .setResource(ClassResource)
        .setMessage('Message data')
        .setCode(200);
    } catch (error) {
      return this.exceptionResponse(error);
    }
}

*Repository

Create repository

node ace make:repository nameRepository

Used on service

construct(nameRepository: NameRepository)
{
  this.nameRepository = nameRepository;
}

async data()
{
    this.nameRepository.functionName();
}

*Resource

Create Resource

node ace make:resource nameResource

*Note: use flag --async to create resource asyncronous

Used on service

construct(nameResource: NameResource)
{
  this.nameResource = nameResource;
}

async data()
{
  try {
    .........
    if (false) {
      throw new CustomException('Error exception');
    }
    ..........

    return this.setData(data)
      .setResource(ClassResource)
      .setMessage('Message data')
      .setCode(200);
  } catch (error) {
    return this.exceptionResponse(error);
  }
}

License

This package is open-sourced software licensed under the MIT license.

1.1.1

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.1.3

9 months ago

1.0.4

9 months ago

1.1.2

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.3

9 months ago

1.0.0

9 months ago

0.0.2

11 months ago