Skip to content

Commit 453700a

Browse files
committed
Some notes on new generator structure
1 parent 7def55e commit 453700a

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

src/schemas/messages.schemas.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { schema, resolver } from '@feathersjs/schema';
2+
3+
export const MessageSchema = schema({
4+
$id: 'message',
5+
properties: {
6+
text: { type: 'string' },
7+
userId: { type: 'number' }
8+
}
9+
});
10+
11+
export const MessageData = resolver(MessageSchema, {
12+
userId (value, message, context) {
13+
return context.params.user?.id;
14+
}
15+
});
16+
17+
export const MessageResult = resolver({
18+
user (value, message, context) {
19+
const { app, params } = context;
20+
21+
return app.service('users').get(message.userId, params);
22+
}
23+
});
24+
25+
export const MessageQuery = feathersQuery({
26+
properties: {}
27+
});

src/schemas/users.schemas.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { schema, resolver } from '@feathersjs/schema';
2+
3+
// We need this to create the MD5 hash
4+
import crypto from 'crypto';
5+
6+
// The Gravatar image service
7+
const gravatarUrl = 'https://s.gravatar.com/avatar';
8+
// The size query. Our chat needs 60px images
9+
const query = 's=60';
10+
11+
export const UserSchema = schema({
12+
$id: 'user',
13+
properties: {
14+
email: { type: 'string' },
15+
password: { type: 'number' },
16+
gravatar: { type: 'string' }
17+
}
18+
});
19+
20+
export const UserData = resolver(UserSchema, {
21+
password (value) {
22+
return hashPassword(value);
23+
},
24+
25+
gravatar (value, user) {
26+
// Gravatar uses MD5 hashes from an email address (all lowercase) to get the image
27+
const hash = crypto.createHash('md5').update(user.email.toLowerCase()).digest('hex');
28+
// Return the full avatar URL
29+
return `${gravatarUrl}/${hash}?${query}`;
30+
}
31+
});
32+
33+
export const UserResult = resolver({
34+
password (value, user, context) {
35+
if (context.params.provider) {
36+
return undefined;
37+
}
38+
39+
return value;
40+
}
41+
});
42+
43+
export const UserQuery = feathersQuery({
44+
properties: {}
45+
});

src/services/messages.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { hooks } from '@feathersjs/hooks';
2+
import { Service } from 'feathers-nedb';
3+
4+
export class MessagesService extends Service {
5+
6+
}
7+
8+
hooks(MessagesService.prototype, [
9+
authenticate('jwt')
10+
]);
11+
12+
hooks(MessageService, {
13+
find: [],
14+
get: [],
15+
create: [],
16+
update: [],
17+
patch: [],
18+
remove: []
19+
});
20+
21+
export function messages (app) {
22+
app.use('messages', new MessagesService());
23+
}

src/services/users.js

Whitespace-only changes.

0 commit comments

Comments
 (0)