@sourceloop/ctrl-plane-tenant-management-service
Version:
Tenant Management microservice for SaaS control plane
70 lines (61 loc) • 1.59 kB
text/typescript
import {belongsTo, model, property} from '@loopback/repository';
import {Tenant} from './tenant.model';
import {ResourceData, ResourceTypes} from '../types';
import {UserModifiableEntity} from '@sourceloop/core';
({
name: 'resources',
description: 'model for resources that are provisioned for a tenant',
})
export class Resource<
T extends ResourceData['metadata'] = ResourceData['metadata'],
>
extends UserModifiableEntity
implements ResourceData
{
({
type: 'string',
id: true,
generated: true,
})
id: string;
({
description:
'identifier for the resource in the external system it was provisioned',
name: 'external_identifier',
type: 'string',
required: true,
})
externalIdentifier: string;
({
description: 'type of the resource like storage, compute, etc',
name: 'type',
type: 'string',
required: true,
})
type: ResourceTypes;
({
description:
'any type specific metadata of the resource like connection info, size, etc',
type: 'object',
required: true,
})
metadata: T;
(
() => Tenant,
{keyTo: 'id'},
{
description: 'id of the tenant for which this resource is provisioned',
name: 'tenant_id',
},
)
tenantId: string;
constructor(data?: Partial<Resource<T>>) {
super(data);
}
}
export interface ResourceRelations {
// describe navigational properties here
tenant?: Tenant;
}
export type ResourceWithRelations<T extends ResourceData['metadata']> =
Resource<T> & ResourceRelations;