Skip to content

Instantly share code, notes, and snippets.

@daffl
Last active April 25, 2019 17:53
Show Gist options
  • Save daffl/ad92905d5f61adc74341c086fe204448 to your computer and use it in GitHub Desktop.
Save daffl/ad92905d5f61adc74341c086fe204448 to your computer and use it in GitHub Desktop.
Feathers Wings sketch outline
@Entity()
class User {
@PrimaryGeneratedColumn()
id: string;
@toLowerCase()
@validate('email')
@Column()
email: string;
@bcrypt()
@protect('external')
@Column()
password: string;
}
@hooks([
authenticate('jwt'),
limitQuery({
id: 'params.user.id'
})
]);
class UserService extends Service<User> {
Model = User;
}
@Entity()
class Message {
@Column()
text: string;
@OneToOne(type => User)
@JoinColumn()
user: User;
}
@hooks([
authenticate('jwt')
]);
class MessageService extends Service<Message> {
Model = Message;
/**
* Create a new user. Will automatically set `userId`
* to the current users id.
*
* @param data The user payload
* @param params Service call parameters
*/
@hooks([
async (context, next) => {
context.data.userId = context.params.user.id;
await next();
}
])
create (data: Message, params: Params) {
return super.create(data, params);
}
}
const app = feathers()
.configure(socketio())
.use('/users', new UserService())
.use('/messages', new MessageService());
app.listen(3030);
@silvestreh
Copy link

how about having @before and @after decorators that can be used at the class and method levels?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment