Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat: storage-offer model
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Feb 2, 2020
1 parent 502b732 commit e974046
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 2 deletions.
52 changes: 52 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@
"@feathersjs/transport-commons": "^4.5.1",
"compression": "^1.7.4",
"cors": "^2.8.5",
"feathers-hooks-common": "^5.0.2",
"feathers-sequelize": "^6.1.0",
"helmet": "^3.21.2",
"pg": "^7.17.1",
"pg-hstore": "^2.3.3",
"reflect-metadata": "^0.1.13",
"sequelize": "^5.21.3",
"sequelize-typescript": "^1.1.0",
"serve-favicon": "^2.5.0",
Expand Down
7 changes: 5 additions & 2 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Application as ExpressFeathers } from '@feathersjs/express'
import { StorageOffer } from './services/storage-offer/storage-offer.service'
import { ServiceAddons } from '@feathersjs/feathers'

// A mapping of service names to types. Will be extended in service files.
export type ServiceTypes = {}

interface ServiceTypes {
'storage-offer': StorageOffer & ServiceAddons<any>
}
// The application instance type that will be used everywhere else
export type Application = ExpressFeathers<ServiceTypes>;
18 changes: 18 additions & 0 deletions src/models/price.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Table, DataType, Column, Model, ForeignKey, BelongsTo } from 'sequelize-typescript'
import StorageOffer from './storage-offer.model'

@Table
export default class Price extends Model {
@Column
period!: number

@Column
amount!: number

@ForeignKey(() => StorageOffer)
@Column
offerId!: number

@BelongsTo(() => StorageOffer)
offer!: StorageOffer
}
17 changes: 17 additions & 0 deletions src/models/storage-offer.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Table, DataType, Column, Model, HasMany } from 'sequelize-typescript'
import Price from './price.model'

@Table
export default class StorageOffer extends Model {
@Column
capacity!: number

@Column
maximumDuration!: number

@Column
address!: string

@HasMany(() => Price)
prices!: Price[]
}
2 changes: 2 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Application } from '../declarations'
import storageOffer from './storage-offer/storage-offer.service'
// Don't remove this comment. It's needed to format import lines nicely.

export default function (app: Application) {
app.configure(storageOffer)
}
33 changes: 33 additions & 0 deletions src/services/storage-offer/storage-offer.hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { disallow } from 'feathers-hooks-common'

export default {
before: {
all: [],
find: [],
get: [],
create: disallow(),
update: disallow(),
patch: disallow(),
remove: disallow()
},

after: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},

error: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
}
};
27 changes: 27 additions & 0 deletions src/services/storage-offer/storage-offer.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Initializes the `StorageOffer` service on path `/storage-offer`
import StorageOffer from '../../models/storage-offer.model'
import hooks from './storage-offer.hooks'
import { Service, SequelizeServiceOptions } from 'feathers-sequelize'
import { Application } from '../../declarations'

export class StorageOfferService extends Service {
constructor (options: Partial<SequelizeServiceOptions>, app: Application) {
super(options)
}
}

export default function (app: Application) {
const options = {
Model: StorageOffer
// Can't be used atm because of https://github.com/sequelize/sequelize/issues/11894
// paginate: app.get('paginate')
}

// Initialize our service with any options it requires
app.use('/storage-offer', new StorageOfferService(options, app))

// Get our initialized service so that we can register hooks
const service = app.service('storage-offer')

service.hooks(hooks)
}
10 changes: 10 additions & 0 deletions test/services/storage-offer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import assert from 'assert';
import app from '../../src/app';

describe('\'StorageOffer\' service', () => {
it('registered the service', () => {
const service = app.service('storage-offer');

assert.ok(service, 'Registered the service');
});
});

0 comments on commit e974046

Please sign in to comment.