This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { hooks, HookContext, NextFunction } from '@feathersjs/hooks'; | |
const logRuntime = async (context: HookContext, next: NextFunction) => { | |
const start = new Date().getTime(); | |
await next(); | |
const end = new Date().getTime(); | |
console.log(`Function '${context.method || '[no name]'}' returned '${context.result}' after ${end - start}ms`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { hooks } = require('@feathersjs/hooks'); | |
const logRuntime = async (context, next) => { | |
const start = new Date().getTime(); | |
await next(); | |
const end = new Date().getTime(); | |
console.log(`Function '${context.method || '[no name]'}' returned '${context.result}' after ${end - start}ms`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { setSchema } = require('@feathersjs/schema'); | |
class User {} | |
setSchema(User, { | |
id: { | |
type: Number | |
}, | |
email: { | |
description: 'The user email', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity() | |
class User { | |
@PrimaryGeneratedColumn() | |
id: string; | |
@toLowerCase() | |
@validate('email') | |
@Column() | |
email: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const service = require('feathers-<database>'); | |
// Allow multi create, patch and remove | |
service({ | |
whitelist: [ '$regex' ] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const service = require('feathers-<database>'); | |
// Allow multi create, patch and remove | |
service({ | |
multi: true | |
}); | |
// Only allow create with an array | |
service({ | |
multi: [ 'create' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Call `get` without running any hooks | |
const message = await app.service('/messages')._get('<message id>'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Will throw `NotFound` if `companyId` does not match | |
// Even if the `id` is available | |
app.service('/messages').get('<message id>', { | |
query: { companyId: '<my company>' } | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const feathers = require('@feathersjs/feathers'); | |
const app = feathers(); | |
app.use('/', myService); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageService { | |
// Find a list of resources | |
find(params) {}, | |
// Get a single resource by its id | |
get(id, params) {}, | |
// Create a new resource | |
create(data, params) {}, | |
// Replace an existing resource by its id with data | |
update(id, data, params) {}, | |
// Merge new data into a resource |