Skip to content

Commit

Permalink
Multiple bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalanamini committed Dec 27, 2018
1 parent f920c51 commit 4a8677c
Show file tree
Hide file tree
Showing 28 changed files with 678 additions and 753 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ os:
- osx

node_js:
- "11"
- "10"
- "9"
- "8"
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

---

## [v0.8.0](https://github.com/foxifyjs/odin/releases/tag/v0.8.0) - *(2018-12-27)*

- :beetle: Fixed `embedMany` relation bug
- :beetle: Fixed not applying `withTrashed` to relations
- :boom: `Types` is now a peerDependency ([`@foxify/schema`](https://github.com/foxifyjs/schema)) which needs to be installed!
- :eyeglasses: Added `embedMany` tests
- :eyeglasses: Added `Node.js` version `11` to tests

## [v0.7.0](https://github.com/foxifyjs/odin/releases/tag/v0.7.0) - *(2018-12-14)*

- :zap: Added `whereHas` method to models
Expand Down
80 changes: 45 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@foxify/odin",
"version": "0.7.5",
"version": "0.8.0",
"description": "Active Record Model",
"author": "Ardalan Amini <[email protected]> [https://github.com/ardalanamini]",
"contributors": [
Expand Down Expand Up @@ -44,8 +44,8 @@
"dependencies": {
"@types/graphql": "^0.13.4",
"@types/graphql-iso-date": "^3.3.1",
"@types/mongodb": "^3.1.17",
"@types/node": "^10.12.15",
"@types/mongodb": "^3.1.18",
"@types/node": "^10.12.18",
"async": "^2.6.1",
"caller-id": "^0.1.0",
"deasync": "^0.1.14",
Expand All @@ -55,18 +55,22 @@
"prototyped.js": "^0.21.0",
"verifications": "^0.3.0"
},
"peerDependencies": {
"@foxify/schema": "^1.0.1"
},
"devDependencies": {
"@foxify/schema": "^1.0.1",
"@types/async": "^2.0.50",
"@types/deasync": "^0.1.0",
"@types/jest": "^23.3.10",
"codecov": "^3.1.0",
"dotenv": "^6.2.0",
"fs-readdir-recursive": "^1.1.0",
"jest": "^23.6.0",
"mongodb-memory-server": "^2.8.0",
"mongodb-memory-server": "^2.9.1",
"rimraf": "^2.6.2",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
"tslint": "^5.12.0",
"tslint-config-airbnb": "^5.11.1",
"typescript": "^3.2.2"
},
Expand Down
22 changes: 9 additions & 13 deletions src/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import * as Odin from ".";
import * as DB from "./DB";
import HasOne from "./Relation/HasOne";
import MorphOne from "./Relation/MorphOne";
import * as Types from "./types";
import TypeAny from "./types/Any";
import TypeArray from "./types/Array";
import TypeDate from "./types/Date";
import TypeObjectId from "./types/ObjectId";
import Types from "./types";
import { array, makeCollectionName, object } from "./utils";

const MODELS: { [name: string]: typeof Odin | undefined } = {};
Expand Down Expand Up @@ -115,26 +111,26 @@ class Base<T extends object = {}> {

const type = schema[key];

if (type instanceof TypeAny) {
if (Types.isType(type)) {
// Type

let schemaType: string = (type as any)._type.toLowerCase();
let schemaType: string = (type as any).constructor.type.toLowerCase();

if (
type instanceof TypeObjectId
|| type instanceof TypeDate
(type.constructor as any).type === "ObjectId"
|| (type.constructor as any).type === "Date"
) schemaType = "string";

properties[key] = {
type: schemaType,
};

if (type instanceof TypeArray) {
let ofSchemaType: string = (type.ofType as any)._type.toLowerCase();
if ((type.constructor as any).type === "Array") {
let ofSchemaType: string = (type as any)._of.constructor.type.toLowerCase();

if (
type.ofType instanceof TypeObjectId
|| type.ofType instanceof TypeDate
ofSchemaType === "objectid"
|| ofSchemaType === "date"
) ofSchemaType = "string";

properties[key].items = {
Expand Down
4 changes: 2 additions & 2 deletions src/DB/Join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class Join<T extends object = any> extends Filter<T> {
protected _shouldPushExpr(value: any) {
if (!string.isString(value)) return false;

return new RegExp(`^${this._ancestor}\..+`).test(value);
return new RegExp(`^\\$?${this._ancestor}\..+`).test(value);
}

protected _where(field: string, operator: string, value: any) {
if (this._shouldPushExpr(value)) {
const keys = array.tail(value.split("."));
const keys = array.tail(value.replace(/^\$/, "").split("."));

keys.push(prepareKey(keys.pop() as string));

Expand Down
Loading

0 comments on commit 4a8677c

Please sign in to comment.