Skip to main content

Class: ServiceBase<Dato>

Abstract base class for services that use TypegooseQueryService.

Type parameters

NameTypeDescription
Datoextends BaseThe Typegoose DAO (document) type.

Hierarchy

  • TypegooseQueryService<Dato>

    ServiceBase

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new ServiceBase<Dato>(model): ServiceBase<Dato>

Type parameters

NameType
Datoextends Base<ObjectId>

Parameters

NameType
modelReturnModelType<() => Dato>

Returns

ServiceBase<Dato>

Overrides

TypegooseQueryService&lt;Dato&gt;.constructor

Defined in

src/bases/serviceBase.ts:10

Properties

Model

Readonly Model: ReturnModelType<() => Dato>

Inherited from

TypegooseQueryService.Model

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:11


filterQueryBuilder

Readonly filterQueryBuilder: FilterQueryBuilder<Dato>

Inherited from

TypegooseQueryService.filterQueryBuilder

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:12


model

Protected Readonly model: ReturnModelType<() => Dato>

Defined in

src/bases/serviceBase.ts:10

Methods

addRelations

addRelations<Relation>(relationName, id, relationIds, opts?): Promise<DocumentType<Dato>>

Type parameters

Name
Relation

Parameters

NameType
relationNamestring
idstring
relationIds(string | number)[]
opts?ModifyRelationOptions<Dato, Relation>

Returns

Promise<DocumentType<Dato>>

Inherited from

TypegooseQueryService.addRelations

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:19


aggregate

aggregate(filter, aggregateQuery): Promise<AggregateResponse<Dato>[]>

Parameters

NameType
filterFilter<Dato>
aggregateQueryAggregateQuery<Dato>

Returns

Promise<AggregateResponse<Dato>[]>

Inherited from

TypegooseQueryService.aggregate

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:28


aggregateRelations

aggregateRelations<Relation>(RelationClass, relationName, entities, filter, aggregate): Promise<Map<DocumentType<Dato>, AggregateResponse<DocumentType<Relation>>[]>>

Type parameters

Name
Relation

Parameters

NameType
RelationClassClass<Relation>
relationNamestring
entitiesDocumentType<Dato>[]
filterFilter<Relation>
aggregateAggregateQuery<Relation>

Returns

Promise<Map<DocumentType<Dato>, AggregateResponse<DocumentType<Relation>>[]>>

Inherited from

TypegooseQueryService.aggregateRelations

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:11

aggregateRelations<Relation>(RelationClass, relationName, dto, filter, aggregate): Promise<AggregateResponse<DocumentType<Relation>>[]>

Type parameters

Name
Relation

Parameters

NameType
RelationClassClass<Relation>
relationNamestring
dtoDocumentType<Dato>
filterFilter<Relation>
aggregateAggregateQuery<Relation>

Returns

Promise<AggregateResponse<DocumentType<Relation>>[]>

Inherited from

TypegooseQueryService.aggregateRelations

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:12


count

count(filter): Promise<number>

Parameters

NameType
filterFilter<Dato>

Returns

Promise<number>

Inherited from

TypegooseQueryService.count

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:29


countRelations

countRelations<Relation>(RelationClass, relationName, entities, filter): Promise<Map<DocumentType<Dato>, number>>

Type parameters

Name
Relation

Parameters

NameType
RelationClassClass<Relation>
relationNamestring
entitiesDocumentType<Dato>[]
filterFilter<Relation>

Returns

Promise<Map<DocumentType<Dato>, number>>

Inherited from

TypegooseQueryService.countRelations

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:13

countRelations<Relation>(RelationClass, relationName, dto, filter): Promise<number>

Type parameters

Name
Relation

Parameters

NameType
RelationClassClass<Relation>
relationNamestring
dtoDocumentType<Dato>
filterFilter<Relation>

Returns

Promise<number>

Inherited from

TypegooseQueryService.countRelations

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:14


createMany

createMany(records): Promise<DocumentType<Dato>[]>

Create multiple entities.

Parameters

NameTypeDescription
recordsDeepPartial<Dato>[]The entities to create.

Returns

Promise<DocumentType<Dato>[]>

Example

const todoItem = await this.service.createMany([
{title: 'Todo Item 1', completed: false },
{title: 'Todo Item 2', completed: true },
]);

Inherited from

TypegooseQueryService.createMany

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:78


createOne

createOne(record): Promise<DocumentType<Dato>>

Creates a single entity.

Parameters

NameTypeDescription
recordDeepPartial<Dato>The entity to create.

Returns

Promise<DocumentType<Dato>>

Example

const todoItem = await this.service.createOne({title: 'Todo Item', completed: false });

Inherited from

TypegooseQueryService.createOne

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:65


deleteMany

deleteMany(filter): Promise<DeleteManyResponse>

Delete multiple records with a @ptc-org/nestjs-query-core Filter.

Parameters

NameTypeDescription
filterFilter<Dato>A Filter to find records to delete.

Returns

Promise<DeleteManyResponse>

Example

const { deletedCount } = this.service.deleteMany({
created: { lte: new Date('2020-1-1') }
});

Inherited from

TypegooseQueryService.deleteMany

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:131


deleteOne

deleteOne(id, opts?): Promise<DocumentType<Dato>>

Delete an entity by id.

Parameters

NameTypeDescription
idstringThe id of the entity to delete.
opts?DeleteOneOptions<Dato>Additional filter to use when finding the entity to delete.

Returns

Promise<DocumentType<Dato>>

Example

const deletedTodo = await this.service.deleteOne(1);

Inherited from

TypegooseQueryService.deleteOne

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:117


findById

findById(id, opts?): Promise<undefined | DocumentType<Dato>>

Find an entity by it's id.

Parameters

NameTypeDescription
idstring | numberThe id of the record to find.
opts?FindByIdOptions<Dato>Additional options

Returns

Promise<undefined | DocumentType<Dato>>

Example

const todoItem = await this.service.findById(1);

Inherited from

TypegooseQueryService.findById

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:40


findRelation

findRelation<Relation>(RelationClass, relationName, dtos, opts?): Promise<Map<Dato, undefined | Relation>>

Type parameters

Name
Relation

Parameters

NameType
RelationClassClass<Relation>
relationNamestring
dtosDocumentType<Dato>[]
opts?FindRelationOptions<Relation>

Returns

Promise<Map<Dato, undefined | Relation>>

Inherited from

TypegooseQueryService.findRelation

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:15

findRelation<Relation>(RelationClass, relationName, dto, opts?): Promise<undefined | DocumentType<Relation>>

Type parameters

Name
Relation

Parameters

NameType
RelationClassClass<Relation>
relationNamestring
dtoDocumentType<Dato>
opts?FindRelationOptions<Relation>

Returns

Promise<undefined | DocumentType<Relation>>

Inherited from

TypegooseQueryService.findRelation

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:16


getById

getById(id, opts?): Promise<DocumentType<Dato>>

Gets an entity by it's id. If the entity is not found a rejected promise is returned.

Parameters

NameTypeDescription
idstringThe id of the record to find.
opts?GetByIdOptions<Dato>Additional options

Returns

Promise<DocumentType<Dato>>

Example

try {
const todoItem = await this.service.getById(1);
} catch(e) {
console.error('Unable to find entity with id = 1');
}

Inherited from

TypegooseQueryService.getById

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:55


query

query(query): Promise<DocumentType<Dato>[]>

Query for multiple entities, using a Query from @ptc-org/nestjs-query-core.

Parameters

NameTypeDescription
queryQuery<Dato>The Query used to filter, page, and sort rows.

Returns

Promise<DocumentType<Dato>[]>

Example

const todoItems = await this.service.query({
filter: { title: { eq: 'Foo' } },
paging: { limit: 10 },
sorting: [{ field: "create", direction: SortDirection.DESC }],
});

Inherited from

TypegooseQueryService.query

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:27


queryRelations

queryRelations<Relation>(RelationClass, relationName, entities, query): Promise<Map<DocumentType<Dato>, DocumentType<Relation>[]>>

Type parameters

Name
Relation

Parameters

NameType
RelationClassClass<Relation>
relationNamestring
entitiesDocumentType<Dato>[]
queryQuery<Relation>

Returns

Promise<Map<DocumentType<Dato>, DocumentType<Relation>[]>>

Inherited from

TypegooseQueryService.queryRelations

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:17

queryRelations<Relation>(RelationClass, relationName, dto, query): Promise<DocumentType<Relation>[]>

Type parameters

Name
Relation

Parameters

NameType
RelationClassClass<Relation>
relationNamestring
dtoDocumentType<Dato>
queryQuery<Relation>

Returns

Promise<DocumentType<Relation>[]>

Inherited from

TypegooseQueryService.queryRelations

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:18


removeRelation

removeRelation<Relation>(relationName, id, relationId, opts?): Promise<DocumentType<Dato>>

Type parameters

Name
Relation

Parameters

NameType
relationNamestring
idstring | number
relationIdstring | number
opts?ModifyRelationOptions<Dato, Relation>

Returns

Promise<DocumentType<Dato>>

Inherited from

TypegooseQueryService.removeRelation

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:22


removeRelations

removeRelations<Relation>(relationName, id, relationIds, opts?): Promise<DocumentType<Dato>>

Type parameters

Name
Relation

Parameters

NameType
relationNamestring
idstring | number
relationIdsnumber[] | string[]
opts?ModifyRelationOptions<Dato, Relation>

Returns

Promise<DocumentType<Dato>>

Inherited from

TypegooseQueryService.removeRelations

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:23


setRelation

setRelation<Relation>(relationName, id, relationId, opts?): Promise<DocumentType<Dato>>

Type parameters

Name
Relation

Parameters

NameType
relationNamestring
idstring | number
relationIdstring | number
opts?ModifyRelationOptions<Dato, Relation>

Returns

Promise<DocumentType<Dato>>

Inherited from

TypegooseQueryService.setRelation

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:21


setRelations

setRelations<Relation>(relationName, id, relationIds, opts?): Promise<DocumentType<Dato>>

Type parameters

Name
Relation

Parameters

NameType
relationNamestring
idstring
relationIds(string | number)[]
opts?ModifyRelationOptions<Dato, Relation>

Returns

Promise<DocumentType<Dato>>

Inherited from

TypegooseQueryService.setRelations

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/reference-query.service.d.ts:20


updateMany

updateMany(update, filter): Promise<UpdateManyResponse>

Update multiple entities with a @ptc-org/nestjs-query-core Filter.

Parameters

NameTypeDescription
updateDeepPartial<Dato>A Partial of entity with the fields to update
filterFilter<Dato>A Filter used to find the records to update

Returns

Promise<UpdateManyResponse>

Example

const { updatedCount } = await this.service.updateMany(
{ completed: true }, // the update to apply
{ title: { eq: 'Foo Title' } } // Filter to find records to update
);

Inherited from

TypegooseQueryService.updateMany

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:104


updateOne

updateOne(id, update, opts?): Promise<DocumentType<Dato>>

Update an entity.

Parameters

NameTypeDescription
idstringThe id of the record.
updateDeepPartial<Dato>A Partial of the entity with fields to update.
opts?UpdateOneOptions<Dato>Additional options

Returns

Promise<DocumentType<Dato>>

Example

const updatedEntity = await this.service.updateOne(1, { completed: true });

Inherited from

TypegooseQueryService.updateOne

Defined in

node_modules/@ptc-org/nestjs-query-typegoose/src/services/typegoose-query-service.d.ts:90