Skip to content

Commit

Permalink
type enchancements on $Model.find(params)
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Feb 16, 2020
1 parent f7b630a commit d8c6a11
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface InternalModelShape {

export type InternalModel = RequireOnlyOne<InternalModelShape, "id" | "uuid">;

export default abstract class MemServerModel {
export default class MemServerModel {
static _DB = {};
static _modelDefinitions = {};
static _attributes = {};
Expand Down Expand Up @@ -102,7 +102,7 @@ export default abstract class MemServerModel {
const foundModel = param.includes(model.id) ? model : null;

return foundModel ? result.concat([foundModel]) : result;
}, []);
}, []) as Array<InternalModel>;
} else if (typeof param !== "number") {
throw new Error(
chalk.red(`[Memserver] ${this.name}.find(id) cannot be called without a valid id`)
Expand All @@ -111,7 +111,7 @@ export default abstract class MemServerModel {

const models = Array.from(this.DB);

return models.find((model) => model.id === param);
return models.find((model) => model.id === param) as InternalModel | undefined;
}
static findBy(options: object): InternalModel | undefined {
if (!options) {
Expand Down Expand Up @@ -287,10 +287,10 @@ export default abstract class MemServerModel {
if (!objectOrArray) {
return;
} else if (Array.isArray(objectOrArray)) {
return objectOrArray.map((object) => this.serialize(object), []);
return (objectOrArray as Array<InternalModel>).map((object) => this.serialize(object), []);
}

return this.serialize(objectOrArray);
return this.serialize(objectOrArray as InternalModel);
}
static serialize(object: InternalModel) {
// NOTE: add links object ?
Expand Down

0 comments on commit d8c6a11

Please sign in to comment.