0.1.3 • Published 7 years ago

auctio v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

Auctio

Auction module written in node.js with Mongodb(mongoose)

Prerequisite

Installation

    $ npm install auctio

Basic Example

Including Auctio

    var auctio = require('auctio');

Initialize Auctio

    auctio.initialize('mongodb://host-information/<db name>').then(init_succes_callback, init_failed_callback);

How to add category

    // Category hierarchy help us to search item by category name
    // Add xxx at top root level
    auctio.addCategory("xxx");

    // Add aaa under xxx
    auctio.addCategory("aaa", {parentName: "xxx"});

    // Add bbb under aaa
    auctio.addCategory("bbb", {parentName: "aaa"});

    // Add yyy under xxx
    auctio.addCategory("yyy", {parentName: "xxx"});

    // Add zzz under yyy
    auctio.addCategory("zzz", {parentName: "yyy"});

How to remove category (and its children)

    // Remove aaa and its child, bbb
    auctio.removeCategory("aaa");

How to offer(sell) item

    var expired_at = new Date();
    expired_at.setDate(expired_at.getDate() + 7); // Expired at next 7 days
    auctio.offerItem('Item Name', 2000, 'zzz', expired_at, "seller's username/token", {buy_out_price: 10000, step_price: 100, brand: 'brand name'})
          .then(offer_success_callback, offer_failed_callback);

How to bid(buy) item

    auctio.bidItem(ObjectId("..."), 4000, "buyer's username/token")
          .then(bid_success_callback, bid_failed_callback);

How to call house-keeping

For finishing sold item (already expired with bidding, buy-out with stepped bidding)

    // This function should be cron/scheduler task
    // It set sold flag for some situations of offered item that has been sold
    //  - expired with bidding
    //  - Bidding price reach buy-out price with auto step price bidding
    // You can pass datetime argument or let the function picking default current datetime
    var keeping_datetime = new Date;
    auctio.houseKeeping(keeping_datetime).then(success_keeping_callback, failed_keeping_callback);

How to query items

    // Searching all item under xxx category
    auctio.searchItemBasic({category: "xxx"});

    // Searching all sold item under zzz category
    auctio.searchItemBasic({sold: true, category: "xxx"});

    // Searching for item with starting price between 1000 and 5000
    auctio.searchItemBasic({begin_range: [1000, 5000]});

    // Searching for item without buy out price
    auctio.searchItemBasic({buy_out: false});

    // For more searching criteria, please see reference below

Terminate Auctio

    terminate_success_callback = function(result) {
      // Do somethings
    }

    terminate_failed_callback = function(error) {
      // Do somethings
    }

    auctio.terminate().then(terminate_succes_callback, terminate_failed_callback);

References

  • initialize

    • Argument
      • db_uri: URI string for connecting to MongoDB (e.g., mongodb://localhost/db_name) (see Mongoose Connection)
      • db_options: Options hash for MongoDB connection parameter (see Mongoose Connection)
      • options: Options hash for Auctio configuration
        • currency_code: Currencty code (Currently unused), default 'THB'
        • max_watch_list: Maximum number of item watch list (Currently unused), default 5
        • max_bid_count: Maximum number of concurrent bidding per user (Currently unused), default 5
        • max_offer_count: Maximum number of concurrent offering per user (Currently unused), default 5
        • default_duration: Default expired duration for offered item, default 3 days
        • image_size: Maximum allowed image size, default 200KBytes
        • max_image_coount: Maximum number of images per item, default 5
        • image_type: Allowed image types, default jpg and png
        • step_price: Default stepping price when bidding with auto step price, default 1
    • Return Value
      • On success: Return Promise with resolved value = true
      • On failure: Return Promise with rejected reason string/error
  • terminate

    • Return Value Return Promise with resolved value = true
  • addCategory

    • Argument
      • name: Category name string
      • options:
        • parentName: Name of parent category
        • description: Description message
    • Return Value
      • On success: Return Promise with resolved value = created category object
      • On failure: Return Promise with rejected reason string/error
  • removeCategory

    • Argument
      • name: Category name to be removed
    • Return Value
      • On success: Return Promise with resolved value = true
      • On failure: Return Promise with rejected reason string/error
  • offerItem

    • Argument
      • name: String name of item to be offered
      • begin_price: Starting price for offered item
      • category: Category name of an item
      • expired_at: Datetime when offered item will be expired
      • seller: String name/token of user who offer an item
      • options:
        • brand: Item brand name
        • description: Item description
        • pictures: Array of picture file paths to be uploaded
        • currency: Currency code for current item price
        • buy_out_price: Offered price for instantly buy out
        • step_price: Stepping price for auto price bidding
    • Return Value
      • On success: Return Promise with resolved value = offered item object
      • On failure: Return Promise with rejected reason string/error
  • bidItem

    • Argument
      • offerItemId: An ObjectId of offered item
      • price: Amount of price for bidding, 0 for auto pricing
      • buyer: String name/token of user who bid an item
    • Return Value
      • On success: Return Promise with resolved value = offered item ObjectId
      • On failure: Return Promise with rejected reason string/error
  • searchItemBasic

    • Argument
      • options:
        • limit: Limited number of item from searching
        • offset: Starting offset of searching results
        • id: Searching by specify ObjectId
        • category: Searching by specify category
        • name: Searching by specify item name
        • brand: Searching by specify item brand name
        • seller: Searching by specify item seller
        • bid_range: Searching by specify range of current bid price min, max, both are inclusive, 0 mean open ended
        • begin_range: Searching by specify range of starting offered price min, max, both are inclusive, 0 mean open ended
        • buy_out_range: Searching by specify range of buy out price min, max, both are inclusive, 0 mean open ended
        • buy_out: Flag to tell whether including item with buy out price or not, if specify buy_out_range, this flag is aut set
        • sold: Flag to tell whether including sold item or not -omits: Array of omitted field names -sort: Hash of sorted fields (e.g., {buy_out_price: -1, name: 1} mean sorted by buy_out_price descending and by name ascending)
    • Return Value
      • On success: Return Promise with resolved value = array of items
      • On failure: Return Promise with rejected reason string/error

Contact

If you have any suggestions, please email to me (natnaka@gmail.com)
0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago