CirclesUBI / circles-api-legacy

User and organization profile service
GNU Affero General Public License v3.0
4 stars 0 forks source link

Offer API #30

Closed edzillion closed 5 years ago

edzillion commented 5 years ago

I am going off the current wireframes.

Offer Model

There are 4 types of offer: item - A Coffee for ©3.50 percentageItem - Pay 20% in © for every Coffee percentageCategory - Pay 20% on all items in © / pay 20% of all main courses in © general - A general call to action - We accept © here!

So our offer model should look like this:

id: { type: 'integer' }, - incremented id gives us sequential order numbers itemCode: { type: 'string' }, - used by organisations that have their own product/item codes type: { type: 'string' }, - type as listed above title: { type: 'string' }, - this will be the headline, so perhaps it should be called 'strapline' or something? description: { type: 'string' }, - this will be inside the fold createdAt: { type: 'object' }, - for admin reasons publishedAt: { type: 'object' }, - this is the time the offer was started updatedAt: { type: 'object' }, - for admin reasons limit: { type: 'object }, - the amount of a good/service you will sell - see below public: { type: 'boolean' }, - should this offer be shown publicly in the 'local offers' section? price: { type: 'float'} - optional, could be a % offer percentage: { type: 'float'} - optional, percentage is the % of the offer to be paid in Circles. category: { type: 'string'} - we could always have a tag system instead but that seems more complicated. @saraswathi can you have a think about this and come up with a list of categories?

Limit Object

There are 3 types of limit: maxCircles - I will accept 500 circles / week maxItems - I will sell 1 item / user / week maxUserCircles - I will sell items worth 50 circles to each user / week

So our limit object should look like this:

type: { type: 'string' }, - type as listed above amount: { type: 'integer' }, - the amount of the type to limit period: { type: 'string' }, - the time period over which the limit is enforced (since publishedAt above) current: { type: 'integer' } - the current amount of item sold

edzillion commented 5 years ago
  return knex.schema.createTable('offer', (t) => {
    t.increments('id').primary()
    t.string('itemCode', 50)
    t.enu('type', ['item', 'percentageItem', 'percentageCategory'], { useNative: true, enumName: 'offer_type' })
    t.string('title', 50).notNullable()
    t.string('description', 250).notNullable()
    t.dateTime('createdAt').notNullable().defaultTo(knex.fn.now())
    t.dateTime('publishedAt')
    t.dateTime('updatedAt')
    t.integer('amount')
    t.boolean('public').notNullable().defaultTo(false)
    t.float('price')
    t.float('percentage')
    t.string('category', 50)
  })
}

@ana0 what exactly does it mean to use postgres native types, as described here? https://knexjs.org/

For Postgres, an additional options argument can be provided to specify whether or not to use Postgres's native TYPE:

table.enu('column', ['value1', 'value2'], { useNative: true, enumName: 'foo_type' })

edzillion commented 5 years ago

@ana0 also how do I declare the enum values in my jsonSchema? I looked around but couldn't find anything that looks like the syntax we are using:

type: { type: 'enum' },

edzillion commented 5 years ago

PR in here: https://github.com/CirclesUBI/circles-api/pull/34

edzillion commented 5 years ago

PR merged