mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-21 23:58:06 +00:00
15 lines
584 B
TypeScript
15 lines
584 B
TypeScript
import { HandlerFunction, Schema, Request } from 'ember-cli-mirage';
|
|
import { pluralize } from 'ember-inflector';
|
|
|
|
interface IGetEntityParams {
|
|
entityType: keyof Schema;
|
|
identifier: string;
|
|
}
|
|
export const getEntity: HandlerFunction = function(schema: Schema, request: Request) {
|
|
const params: IGetEntityParams | undefined = (request.params as unknown) as IGetEntityParams;
|
|
const db = schema[params?.entityType] || schema[pluralize((params?.entityType as string) || '')];
|
|
const results = db.where({ urn: params?.identifier });
|
|
|
|
return this.serialize(results.models[0]);
|
|
};
|