Skip to content

Latest commit

 

History

History
67 lines (54 loc) · 1.13 KB

_.md

File metadata and controls

67 lines (54 loc) · 1.13 KB

Plan to split project

  • node-data
    • standalone-node-odata
    • express-node-odata
    • koa-node-odata
    • egg-node-odata
  • node-odata-core
    • node-odata-parser
    • node-odata-metadata
  • node-odata-adapter
    • node-odata-mongodb

next version to write

import { Resource } from 'node-odata';

const model = {
  title: String,
  price: Number,
};

function checkUserAuth() {}
function router() {}
function queryable() {}

export default class Book extends Resource {
  constructor() {
    super('book', model);
  }

  @queryable({ pageSize: 10, maxTop: 100 })
  async onGetList(next) {
    const entities = await next();
  }

  async onGet(next) {
    // do something before
    const entity = await next();
    // dosomething after
  }

  async onCreate(next) {
    const entity = await next();
  }

  @checkUserAuth
  async onRemove(next) {
    const entity = await next();
  }

  @checkUserAuth
  async onUpdate(next) {
    const entity = await next();
  }

  @router['/50off']
  async halfPriceAction(id, query) {
    const entity = await this.findOneById(id);
    entity.price /= 2;
    await entity.save();
    return entity;
  }
}