Fully Typed Collection

Implementation for a collection resource that is fully typed:

import { Injectable } from '@angular/core';
import { ApiUrl, ApiRoute, CrudService } from 'ngx-crud';
import { RequestBody, ResponseBody } from './example.interface';

import { environment } from '@environments';

@Injectable()
@ApiUrl(environment.apiUrl)
@ApiRoute(environment.apiRoutes.example)
export class ExampleService extends CrudService<RequestBody, ResponseBody>
{
}

Each method types are generated by this default mapping:

RequestBody,
ResponseBody,
CreateRequestBody = RequestBody,
CreateResponseBody = ResponseBody,
ReadResponseBody = ResponseBody,
FindResponseBody = ResponseBody[],
UpdateRequestBody = RequestBody,
UpdateResponseBody = ResponseBody,
PatchRequestBody = Partial<RequestBody>,
PatchResponseBody = ResponseBody,
DeleteResponseBody = ResponseBody,
CustomRequestBody = RequestBody,
CustomResponseBody = ResponseBody | ResponseBody[]

Create a CrudServiceCustom that meets your API standard:

import { Injectable } from '@angular/core';
import { CrudService } from 'ngx-crud';

@Injectable()
export class CrudServiceCustom<
	RequestBody,
	ResponseBody,
	CreateRequestBody = RequestBody,
	CreateResponseBody = ResponseBody,
	ReadResponseBody = ResponseBody,
	FindResponseBody = ResponseBody[],
	UpdateRequestBody = RequestBody,
	UpdateResponseBody = void,
	PatchRequestBody = Partial<RequestBody>,
	PatchResponseBody = void,
	DeleteResponseBody = void,
	CustomRequestBody = RequestBody,
	CustomResponseBody = ResponseBody | ResponseBody[]
> extends CrudService<
	RequestBody,
	ResponseBody,
	CreateRequestBody,
	CreateResponseBody,
	ReadResponseBody,
	FindResponseBody,
	UpdateRequestBody,
	UpdateResponseBody,
	PatchRequestBody,
	PatchResponseBody,
	DeleteResponseBody,
	CustomRequestBody,
	CustomResponseBody
>
{
}

Last updated