Last active
April 25, 2019 17:53
-
-
Save daffl/ad92905d5f61adc74341c086fe204448 to your computer and use it in GitHub Desktop.
Feathers Wings sketch outline
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; | |
@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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about having
@before
and@after
decorators that can be used at theclass
and method levels?