2020-09-03 10:37:02 -07:00
|
|
|
import { HandlerFunction, Schema, Request } from 'ember-cli-mirage';
|
2020-10-13 11:40:01 -07:00
|
|
|
import { pluralize } from 'ember-inflector';
|
2020-09-03 10:37:02 -07:00
|
|
|
|
|
|
|
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;
|
2020-10-13 11:40:01 -07:00
|
|
|
const db = schema[params?.entityType] || schema[pluralize((params?.entityType as string) || '')];
|
2020-09-03 10:37:02 -07:00
|
|
|
const results = db.where({ urn: params?.identifier });
|
|
|
|
|
|
|
|
return this.serialize(results.models[0]);
|
|
|
|
};
|