11import { FastifyInstance , FastifyReply , FastifyRequest } from "fastify" ;
22import { track } from "../lib/hog" ;
3- import { checkToken } from "../lib/jwt" ;
43import { prisma } from "../prisma" ;
54
65export function clientRoutes ( fastify : FastifyInstance ) {
@@ -9,32 +8,27 @@ export function clientRoutes(fastify: FastifyInstance) {
98 "/api/v1/client/create" ,
109
1110 async ( request : FastifyRequest , reply : FastifyReply ) => {
12- const bearer = request . headers . authorization ! . split ( " " ) [ 1 ] ;
13- const token = checkToken ( bearer ) ;
14-
15- if ( token ) {
16- const { name, email, number, contactName } : any = request . body ;
17-
18- const client = await prisma . client . create ( {
19- data : {
20- name,
21- contactName,
22- email,
23- number : String ( number ) ,
24- } ,
25- } ) ;
26-
27- const hog = track ( ) ;
28-
29- hog . capture ( {
30- event : "client_created" ,
31- distinctId : client . id ,
32- } ) ;
33-
34- reply . send ( {
35- success : true ,
36- } ) ;
37- }
11+ const { name, email, number, contactName } : any = request . body ;
12+
13+ const client = await prisma . client . create ( {
14+ data : {
15+ name,
16+ contactName,
17+ email,
18+ number : String ( number ) ,
19+ } ,
20+ } ) ;
21+
22+ const hog = track ( ) ;
23+
24+ hog . capture ( {
25+ event : "client_created" ,
26+ distinctId : client . id ,
27+ } ) ;
28+
29+ reply . send ( {
30+ success : true ,
31+ } ) ;
3832 }
3933 ) ;
4034
@@ -43,26 +37,21 @@ export function clientRoutes(fastify: FastifyInstance) {
4337 "/api/v1/client/update" ,
4438
4539 async ( request : FastifyRequest , reply : FastifyReply ) => {
46- const bearer = request . headers . authorization ! . split ( " " ) [ 1 ] ;
47- const token = checkToken ( bearer ) ;
48-
49- if ( token ) {
50- const { name, email, number, contactName, id } : any = request . body ;
51-
52- await prisma . client . update ( {
53- where : { id : id } ,
54- data : {
55- name,
56- contactName,
57- email,
58- number : String ( number ) ,
59- } ,
60- } ) ;
61-
62- reply . send ( {
63- success : true ,
64- } ) ;
65- }
40+ const { name, email, number, contactName, id } : any = request . body ;
41+
42+ await prisma . client . update ( {
43+ where : { id : id } ,
44+ data : {
45+ name,
46+ contactName,
47+ email,
48+ number : String ( number ) ,
49+ } ,
50+ } ) ;
51+
52+ reply . send ( {
53+ success : true ,
54+ } ) ;
6655 }
6756 ) ;
6857
@@ -71,17 +60,12 @@ export function clientRoutes(fastify: FastifyInstance) {
7160 "/api/v1/clients/all" ,
7261
7362 async ( request : FastifyRequest , reply : FastifyReply ) => {
74- const bearer = request . headers . authorization ! . split ( " " ) [ 1 ] ;
75- const token = checkToken ( bearer ) ;
63+ const clients = await prisma . client . findMany ( { } ) ;
7664
77- if ( token ) {
78- const clients = await prisma . client . findMany ( { } ) ;
79-
80- reply . send ( {
81- success : true ,
82- clients : clients ,
83- } ) ;
84- }
65+ reply . send ( {
66+ success : true ,
67+ clients : clients ,
68+ } ) ;
8569 }
8670 ) ;
8771
@@ -90,20 +74,15 @@ export function clientRoutes(fastify: FastifyInstance) {
9074 "/api/v1/clients/:id/delete-client" ,
9175
9276 async ( request : FastifyRequest , reply : FastifyReply ) => {
93- const bearer = request . headers . authorization ! . split ( " " ) [ 1 ] ;
94- const token = checkToken ( bearer ) ;
95-
96- if ( token ) {
97- const { id } : any = request . params ;
77+ const { id } : any = request . params ;
9878
99- await prisma . client . delete ( {
100- where : { id : id } ,
101- } ) ;
79+ await prisma . client . delete ( {
80+ where : { id : id } ,
81+ } ) ;
10282
103- reply . send ( {
104- success : true ,
105- } ) ;
106- }
83+ reply . send ( {
84+ success : true ,
85+ } ) ;
10786 }
10887 ) ;
10988}
0 commit comments