@sourceloop/ctrl-plane-tenant-management-service
Version:
Tenant Management microservice for SaaS control plane
246 lines (235 loc) • 6.27 kB
text/typescript
import {
Count,
CountSchema,
Filter,
repository,
Where,
} from '@loopback/repository';
import {del, get, param, patch, post, put, requestBody} from '@loopback/rest';
import {
CONTENT_TYPE,
getModelSchemaRefSF,
OPERATION_SECURITY_SPEC,
STATUS_CODE,
} from '@sourceloop/core';
import {authenticate, STRATEGY} from 'loopback4-authentication';
import {authorize} from 'loopback4-authorization';
import {ContactRepository} from '../repositories/contact.repository';
import {Contact} from '../models';
import {PermissionKey} from '../permissions';
const basePath = '/contacts';
export class ContactController {
/**
* The constructor function initializes a ContactRepository instance for managing contact data.
* @param {ContactRepository} contactRepository - The `contactRepository` parameter is an instance of
* the `ContactRepository` class that is being injected into the constructor using dependency
* injection. This allows the class to have access to the methods and properties of the
* `ContactRepository` class within its own methods.
*/
constructor(
public contactRepository: ContactRepository,
) {}
async create(
contact: Omit<Contact, 'id'>,
): Promise<Contact> {
return this.contactRepository.create(contact);
}
async count(.where(Contact) where?: Where<Contact>): Promise<Count> {
return this.contactRepository.count(where);
}
async find(
.filter(Contact) filter?: Filter<Contact>,
): Promise<Contact[]> {
return this.contactRepository.find(filter);
}
async updateAll(
contact: Contact,
.where(Contact) where?: Where<Contact>,
): Promise<Count> {
return this.contactRepository.updateAll(contact, where);
}
async findById(
.path.string('id') id: string,
.filter(Contact, {exclude: 'where'})
filter?: Filter<Contact>,
): Promise<Contact> {
return this.contactRepository.findById(id, filter);
}
async updateById(
.path.string('id') id: string,
contact: Contact,
): Promise<void> {
await this.contactRepository.updateById(id, contact);
}
async replaceById(
.path.string('id') id: string,
contact: Contact,
): Promise<void> {
await this.contactRepository.replaceById(id, contact);
}
async deleteById(.path.string('id') id: string): Promise<void> {
await this.contactRepository.deleteById(id);
}
}