-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
50 lines (48 loc) · 1.25 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import {createServer, Model, Response} from 'miragejs';
createServer({
urlPrefix: 'http://localhost:8080',
namespace: 'api',
models: {
user: Model,
},
seeds(server) {
server.create('user', {
firstName: 'Ismael',
lastName: 'Sousa',
email: '[email protected]',
password: 'B4gJQR@o@AnXVkU!A4CaYJl68LR!jhuVm&flaPu$C*0',
token: 'eyasdjasdnansasdna3e33ne3_3d3nd3djnd',
avatar: 'https://avatars.githubusercontent.com/u/28990749?v=4',
});
},
routes() {
this.get('/user', schema => {
return schema.users.all();
});
this.post('/auth', (schema, request) => {
const body = JSON.parse(request.requestBody);
const user = schema.users.findBy({
email: body.email,
password: body.password,
});
if (!user) {
return new Response(404);
}
return user;
});
this.post('/user', (schema, request) => {
/** requestBody
firstName: string;
lastName: string;
token: string;
password: string;
*/
const body = JSON.parse(request.requestBody);
const user = schema.users.create({
...body,
token: 'eyasjdandajdnad_edadade-adeadax341',
});
return user;
});
},
});