Skip to content

Commit

Permalink
Merge branch 'development' of github.com:foxifyjs/foxify-restify-odin…
Browse files Browse the repository at this point in the history
… into development
  • Loading branch information
ardalanamini committed Jan 7, 2019
2 parents 341141c + 451a75e commit 7e8ee6a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

---

## [v1.7.0](https://github.com/foxifyjs/foxify-restify-odin/releases/tag/v1.7.0) - *(2019-01-02)*

- :star2: Added ability to add `pre` handler to all routes
- :boom: Changed filter operator `ex` to `exists`
- :boom: Changed filter operator `lk` to `like`
- :boom: Changed filter operator `nlk` to `nlike`

## [v1.6.0](https://github.com/foxifyjs/foxify-restify-odin/releases/tag/v1.6.0) - *(2018-12-28)*

- :star2: Added ability to use `has` filter in the first `and` level
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ app.start();

```typescript
type Operator = "lt" | "lte" | "eq" | "ne" | "gte" | "gt" |
"ex" | "in" | "nin" | "bet" | "nbe" | "lk" | "nlk";
"exists" | "in" | "nin" | "bet" | "nbe" | "like" | "nlike";

interface FilterObject {
field: string;
Expand All @@ -96,8 +96,8 @@ interface Query {
}

interface RouteOptions {
pre?: Foxify.Handler;
post?: Foxify.Handler;
pre?: Foxify.Handler | Foxify.Handler[];
post?: Foxify.Handler | Foxify.Handler[];
}

interface RoutesOptions {
Expand All @@ -113,6 +113,7 @@ interface Options {
name: string;
prefix: string;
defaults: Query;
pre?: Foxify.Handler | Foxify.Handler[];
routes: Partial<RoutesOptions>;
}

Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "foxify-restify-odin",
"version": "1.6.0",
"version": "1.7.0",
"description": "Easily restify odin databases",
"author": "Ardalan Amini <[email protected]> [https://github.com/ardalanamini]",
"license": "MIT",
Expand Down Expand Up @@ -45,7 +45,7 @@
"@foxify/odin": "^0.8.0",
"@foxify/schema": "^1.0.1",
"@types/body-parser": "^1.17.0",
"@types/jest": "^23.3.10",
"@types/jest": "^23.3.11",
"@types/qs": "^6.5.1",
"body-parser": "^1.18.3",
"codecov": "^3.1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/builders/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const operate = (query: typeof Odin, field: string, operator: Operator, value: a
case "gte":
case "gt":
return query.where(field, BASIC_OPERATORS[operator], value);
case "ex":
case "exists":
if (value === true) return query.whereNotNull(field);
return query.whereNull(field);
case "in":
Expand All @@ -31,9 +31,9 @@ const operate = (query: typeof Odin, field: string, operator: Operator, value: a
return query.whereBetween(field, value[0], value[1]);
case "nbe":
return query.whereNotBetween(field, value[0], value[1]);
case "lk":
case "like":
return query.whereLike(field, value);
case "nlk":
case "nlike":
return query.whereNotLike(field, value);
default:
throw new TypeError("Unknown operator");
Expand Down
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import query from "./query";

namespace restify {
export type Operator = "lt" | "lte" | "eq" | "ne" | "gte" | "gt" |
"ex" | "in" | "nin" | "bet" | "nbe" | "lk" | "nlk";
"exists" | "in" | "nin" | "bet" | "nbe" | "like" | "nlike";

export interface FilterObject {
field: string;
Expand Down Expand Up @@ -42,8 +42,8 @@ namespace restify {
}

export interface RouteOptions {
pre?: Foxify.Handler;
post?: Foxify.Handler;
pre?: Foxify.Handler | Foxify.Handler[];
post?: Foxify.Handler | Foxify.Handler[];
}

export interface RoutesOptions {
Expand All @@ -60,6 +60,7 @@ namespace restify {
prefix: string;
qs: IParseOptions;
defaults: Query;
pre?: Foxify.Handler | Foxify.Handler[];
routes: P extends true ? Partial<RoutesOptions> : RoutesOptions;
}
}
Expand Down Expand Up @@ -118,6 +119,7 @@ const restify = (model: typeof Odin, options: Partial<restify.Options<true>> = {
router.get(
"",
foxifyRestifyOdin(),
options.pre as any,
routes.index.pre as any,
index(options as restify.Options),
routes.index.post as any,
Expand All @@ -129,6 +131,7 @@ const restify = (model: typeof Odin, options: Partial<restify.Options<true>> = {
router.get(
"/count",
foxifyRestifyOdin(),
options.pre as any,
routes.count.pre as any,
count(options as restify.Options),
routes.count.post as any,
Expand All @@ -139,6 +142,7 @@ const restify = (model: typeof Odin, options: Partial<restify.Options<true>> = {
if (routes.store) {
router.post(
"",
options.pre as any,
routes.store.pre as any,
store(model, options as restify.Options),
routes.store.post as any,
Expand All @@ -150,6 +154,7 @@ const restify = (model: typeof Odin, options: Partial<restify.Options<true>> = {
router.get(
`/:${name}`,
foxifyRestifyOdin(true),
options.pre as any,
routes.show.pre as any,
show(model, options as restify.Options),
routes.show.post as any,
Expand All @@ -160,6 +165,7 @@ const restify = (model: typeof Odin, options: Partial<restify.Options<true>> = {
if (routes.update) {
router.patch(
`/:${name}`,
options.pre as any,
routes.update.pre as any,
update(model, options as restify.Options),
routes.update.post as any,
Expand All @@ -170,6 +176,7 @@ const restify = (model: typeof Odin, options: Partial<restify.Options<true>> = {
if (routes.delete) {
router.delete(
`/:${name}`,
options.pre as any,
routes.delete.pre as any,
deleteController(model, options as restify.Options),
routes.delete.post as any,
Expand Down
2 changes: 1 addition & 1 deletion test/count/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ it("Should filter (6)", async () => {
{
filter: {
field: "name.first",
operator: "lk",
operator: "like",
value: "arda",
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/index/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ it("Should filter (6)", async () => {
{
filter: {
field: "name.first",
operator: "lk",
operator: "like",
value: "arda",
},
},
Expand Down

0 comments on commit 7e8ee6a

Please sign in to comment.