소스 검색

update puesto with mutation

amenpunk 2 년 전
부모
커밋
1317cbfaaf

+ 7 - 1
src/App.js

@@ -9,7 +9,13 @@ import { QueryClient, QueryClientProvider } from 'react-query'
9 9
 import { ReactQueryDevtools } from 'react-query/devtools'
10 10
 
11 11
 import Routes from './Components/Routes'
12
-const queryClient = new QueryClient()
12
+const queryClient = new QueryClient({
13
+    defaultOptions: {
14
+        queries: {
15
+            refetchOnWindowFocus: false,
16
+        },
17
+    },
18
+})
13 19
 
14 20
 const GATEWAY = {
15 21
     dev: {

+ 97 - 83
src/Components/Modal/EditPlaza.js

@@ -1,105 +1,118 @@
1
-import React, { useEffect, memo } from 'react';
1
+import React, { memo, useCallback, useMemo, useEffect } from 'react';
2 2
 import * as Yup from 'yup';
3 3
 import { useFormik, Form, FormikProvider } from 'formik';
4 4
 import { Modal } from 'react-bootstrap'
5 5
 
6 6
 import DateFnsUtils from '@date-io/date-fns';
7
-import { DesktopDatePicker,LocalizationProvider } from '@mui/lab';
7
+import { DesktopDatePicker, LocalizationProvider } from '@mui/lab';
8 8
 
9
-import {  
10
-    Button, Stack, TextField, MenuItem,FormControl, InputLabel, Select,
9
+import {
10
+    Button, Stack, TextField, MenuItem, FormControl, InputLabel, Select,
11 11
     Backdrop, CircularProgress
12 12
 } from '@mui/material';
13 13
 
14 14
 import { Service } from '../../Utils/HTTP';
15
-import  useAuth from '../../Auth/useAuth';
15
+import useAuth from '../../Auth/useAuth';
16
+import { useQuery, useMutation, useQueryClient } from 'react-query'
17
+
18
+const NewPlazaSchema = Yup.object().shape({
19
+    id: Yup.number(),
20
+    nombrepuesto:
21
+        Yup.string().required('El nombre es requerido')
22
+            .min(5, "El nombre del  puesto debe ser mayor a 5 caracteres")
23
+            .max(100),
24
+    puestosuperior: Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
25
+    aredepto: Yup.number().required('Escoge alguna área'),
26
+    fecha: Yup.date("Ingresa una fecha válida"),
27
+    notas: Yup.string("Ingresa una nota válida").min(5).max(150),
28
+})
29
+
30
+
16 31
 
17 32
 function Edit(props) {
18 33
 
19
-    const NewPlazaSchema = Yup.object().shape({
20
-        id: Yup.number(),
21
-        nombrepuesto : 
22
-        Yup.string().required('El nombre es requerido')
23
-        .min(5, "El nombre del  puesto debe ser mayor a 5 caracteres")
24
-        .max(100),
25
-        puestosuperior : Yup.number("El puesto superior debe ser un número").required("El puesto es requerido"),
26
-        aredepto : Yup.number().required('Escoge alguna área'),
27
-        fecha : Yup.date("Ingresa una fecha válida"),
28
-        notas : Yup.string("Ingresa una nota válida").min(5).max(150),
29
-    })
30
-    
34
+    const now = useMemo(() => new Date(), [])
35
+    const auth = useAuth();
36
+    const token = auth.getToken();
37
+    const queryClient = useQueryClient()
38
+    let { visible, toggle, puesto } = props
39
+
31 40
     const [departamento, setDepartamento] = React.useState('');
32
-    const [open, setOpen] = React.useState(false);
33
-    const handleClose = () => false
41
+    // const [open, setOpen] = React.useState(false);
34 42
 
35
-    const changeDepartamento = (event) => {
43
+    const changeDepartamento = useCallback((event) => {
36 44
         setDepartamento(event.target.value);
37
-    };
45
+    }, []);
38 46
 
47
+    const [date, setDate] = React.useState(now);
48
+
49
+    const getCategories = async () => {
50
+        let rest = new Service("/categoria/getAll")
51
+        return await rest.getQuery(token)
52
+    }
53
+
54
+    const updatePuesto = async (fields) => {
55
+        let rest = new Service('/plaza/edit');
56
+        return rest.putQuery(fields, token)
57
+    }
58
+
59
+    const puestoMutation = useMutation(updatePuesto)
60
+
61
+    const close = () => toggle("EDIT");
62
+
63
+    const { data } = useQuery('categories', getCategories);
39 64
 
40
-    const [date, setDate] = React.useState(new Date());
41
-    const auth = useAuth();
42
-    const token = auth.getToken();
43 65
 
44
-    let {onClose, puesto : { data }, Complete, visible, categorias  } = props
45
-    
46 66
     const formik = useFormik({
47 67
         initialValues: {
48
-            id: data ? data.id :"",
49
-            nombrepuesto: data ? data.nombrepuesto :"",
50
-            puestosuperior:data ?data.puestosuperior :"",
68
+            id: 1,
69
+            nombrepuesto: "",
70
+            puestosuperior: 1,
51 71
             aredepto: 1,
52
-            fecha: date,
53
-            notas:data? data.notas :"",
72
+            fecha: now,
73
+            notas: ""
54 74
         },
55
-        onSubmit: ( fields, { resetForm } ) => {
56
-            setOpen(true)
57
-            fields['fecha'] =  new Date(fields.fecha).toISOString();
58
-
59
-            let Rest = new Service('/plaza/edit');
60
-            Rest
61
-            .put( fields, token )
62
-            .then( _ => {
63
-                resetForm();
64
-                Complete(true,"Puesto actualizado exitosamente");
65
-                onClose();
66
-                setOpen(false)
67
-            })
68
-            .catch(err => {
69
-                console.error(err)
70
-                Complete(false,"Ocurrio un error, intentalo nuevamente");
71
-                setOpen(false)
75
+        onSubmit: (fields, { resetForm }) => {
76
+            fields['fecha'] = new Date(fields.fecha).toISOString();
77
+
78
+            puestoMutation.mutate(fields, {
79
+                onSuccess: () => {
80
+                    close();
81
+                    queryClient.invalidateQueries('puestos')
82
+                }
72 83
             })
73 84
 
85
+            resetForm();
74 86
         },
75 87
         validationSchema: NewPlazaSchema,
76 88
     });
77 89
 
78
-    const { errors, touched, handleSubmit, getFieldProps, setValues} = formik;
79
-    
80
-    useEffect(() => {
81
-        setValues({
82
-            id: data? data.id:"",
83
-            nombrepuesto: data? data.nombrepuesto:"",
84
-            notas:data?data.notas:"",
85
-            puestosuperior:data ?data.puestosuperior :"",
86
-            aredepto: 1,
87
-            fecha:data?new Date(data.create_day): new Date(),
88
-        })
89
-
90
-    },[data,setValues])
90
+    const { errors, touched, handleSubmit, getFieldProps, setValues } = formik;
91 91
 
92
+    useEffect(() => {
93
+        console.log("PUESTO :: ", puesto)
94
+        if (puesto) {
95
+            setValues({
96
+                id: puesto.id,
97
+                nombrepuesto: puesto.nombrepuesto,
98
+                puestosuperior: puesto.puestosuperior,
99
+                aredepto: puesto.areadeptoplz_id,
100
+                fecha: new Date(puesto.create_day),
101
+                notas: puesto.notas
102
+            })
103
+        }
104
+    }, [puesto, now, setValues])
92 105
 
93 106
     return (
94 107
 
95
-        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={onClose}>
108
+        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={close}>
96 109
             <Modal.Header>
97
-                <button onClick={onClose}  type="button" className="close" data-dismiss="modal">&times;</button>
98
-                <h4 className="modal-title" style={{color : '#252525'}}>Agregar plaza</h4>
110
+                <button onClick={close} type="button" className="close" data-dismiss="modal">&times;</button>
111
+                <h4 className="modal-title" style={{ color: '#252525' }}>Editar puesto</h4>
99 112
             </Modal.Header>
100 113
             <Modal.Body className="modal-body">
101 114
 
102
-                <FormikProvider style={{ padding : 25 }} value={formik}>
115
+                <FormikProvider style={{ padding: 25 }} value={formik}>
103 116
                     <Form autoComplete="off" noValidate onSubmit={handleSubmit}>
104 117
                         <Stack spacing={3}>
105 118
 
@@ -133,33 +146,34 @@ function Edit(props) {
133 146
                                         {...getFieldProps('aredepto')}
134 147
                                         error={Boolean(touched.aredepto && errors.aredepto)} >
135 148
                                         {
136
-                                        categorias ?
137
-                                            categorias.map( cate => {
138
-                                                return (
139
-                                                    <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
140
-                                                )
141
-                                            })
142
-                                            : <MenuItem>Null</MenuItem>
149
+                                            data ?
150
+                                                data.data.map(cate => {
151
+                                                    return (
152
+                                                        <MenuItem key={cate.id} value={cate.id}>{cate.nombre}</MenuItem>
153
+                                                    )
154
+                                                })
155
+                                                : <MenuItem>Null</MenuItem>
143 156
                                         }
144 157
                                     </Select>
145 158
                                 </FormControl>
146 159
 
147 160
 
148
-                                <LocalizationProvider 
161
+                                <LocalizationProvider
149 162
                                     dateAdapter={DateFnsUtils}>
150 163
                                     <DesktopDatePicker
151 164
                                         label="Fecha Creación"
152 165
                                         fullWidth
153 166
                                         inputFormat="dd/MM/yyyy"
154 167
                                         {...getFieldProps('fecha')}
168
+                                        xd
155 169
                                         value={date}
156 170
                                         onChange={setDate}
157
-                                        renderInput={(params) => 
158
-                                            <TextField 
171
+                                        renderInput={(params) =>
172
+                                            <TextField
159 173
                                                 disabled={true}
160 174
                                                 label="Fecha Creación"
161 175
                                                 fullWidth
162
-                                                {...params} 
176
+                                                {...params}
163 177
                                             />}
164 178
                                     />
165 179
                                 </LocalizationProvider>
@@ -171,7 +185,6 @@ function Edit(props) {
171 185
                                     id="filled-multiline-static"
172 186
                                     multiline
173 187
                                     rows={4}
174
-                                    defaultValue="Default Value"
175 188
                                     variant="filled"
176 189
                                     label="Notas"
177 190
                                     fullWidth
@@ -179,7 +192,7 @@ function Edit(props) {
179 192
                                     {...getFieldProps('notas')}
180 193
                                     error={Boolean(touched.notas && errors.notas)}
181 194
                                     helperText={touched.notas && errors.notas}
182
-                                    />
195
+                                />
183 196
                             </Stack>
184 197
                         </Stack>
185 198
 
@@ -187,7 +200,7 @@ function Edit(props) {
187 200
                         <Modal.Footer>
188 201
                             <Button
189 202
                                 type="submit"
190
-                                className="registerBtn" 
203
+                                className="registerBtn"
191 204
                                 variant="contained"
192 205
                                 sx={{ mt: 1, mr: 1 }} >
193 206
                                 {'Actualizar'}
@@ -198,10 +211,11 @@ function Edit(props) {
198 211
                 </FormikProvider>
199 212
             </Modal.Body>
200 213
             <Backdrop
201
-                sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
202
-                open={open}
203
-                onClick={handleClose} >
204
-            <CircularProgress color="inherit" />
214
+            // sx={{ color: '#fd4b4b', zIndex: (theme) => theme.zIndex.drawer + 1 }}
215
+            // open={open}
216
+            // onClick={() => console.log('backdrop')} >
217
+            >
218
+                <CircularProgress color="inherit" />
205 219
             </Backdrop>
206 220
 
207 221
         </Modal>

+ 14 - 16
src/Components/Modal/MostrarPlaza.js

@@ -1,19 +1,17 @@
1
-import React, {memo} from 'react';
1
+import React, { memo } from 'react';
2 2
 import { Modal, Col, Row } from 'react-bootstrap'
3 3
 import QA from '../../Images/puesto.jpg'
4 4
 
5 5
 function Mostrar(props) {
6 6
 
7
-    let { visible, onClose, puesto } = props
8
-
7
+    let { visible, puesto } = props
9 8
     const opciones = { weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' };
9
+    const close = () => props.toggle("VER");
10 10
 
11
-    console.log(puesto)
12
-
13
-    return(
14
-        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered  show={visible} onHide={onClose}>
11
+    return (
12
+        <Modal size="lg" aria-labelledby="contained-modal-title-vcenter" centered show={visible} onHide={close}>
15 13
             <Modal.Header>
16
-                <button  onClick={onClose} type="button" className="close" data-dismiss="modal">&times;</button>
14
+                <button onClick={close} type="button" className="close" data-dismiss="modal">&times;</button>
17 15
                 <h4 className="modal-title">Mostrar plaza</h4>
18 16
             </Modal.Header>
19 17
             <Modal.Body className="modal-body">
@@ -22,17 +20,17 @@ function Mostrar(props) {
22 20
                     <Row >
23 21
                         <Col md="4">
24 22
                             <div className="img-container">
25
-                                <img alt='not found cooo' src={QA}/>
23
+                                <img alt='not found cooo' src={QA} />
26 24
                             </div>
27 25
                         </Col>
28 26
                         <Col md="8">
29
-                            <input value={puesto.nombre} type="text" name="nombre" placeholder="..." readOnly/>
30
-                            <input value={puesto.description} type="text" name="descript" placeholder="..." readOnly/>
31
-                            <input 
32
-                                value={ new Date( puesto.created ).toLocaleDateString('es-GT',opciones) } 
33
-                                type="text" 
34
-                                placeholder="...." 
35
-                                name="sku" readOnly/>
27
+                            <input value={puesto ? puesto.nombrepuesto : "..."} type="text" name="nombre" placeholder="..." readOnly />
28
+                            <input value={puesto ? puesto.notas : '...'} type="text" name="descript" placeholder="..." readOnly />
29
+                            <input
30
+                                value={new Date(puesto ? puesto.createday : new Date()).toLocaleDateString('es-GT', opciones)}
31
+                                type="text"
32
+                                placeholder="...."
33
+                                name="sku" readOnly />
36 34
                         </Col>
37 35
                     </Row>
38 36
                 </div>

+ 0 - 71
src/Components/Navigation/MainListItems.jsx

@@ -1,71 +0,0 @@
1
-import React from 'react';
2
-
3
-import { 
4
-    Home, Fingerprint, History, MiscellaneousServices , 
5
-    Work, VisibilityOff, PeopleAlt, Equalizer,
6
-    ExpandLess, ExpandMore
7
-} from '@mui/icons-material/'
8
-
9
-
10
-import { Collapse,ListItem, List ,ListItemIcon,ListItemText,ListSubheader } from '@mui/material/'
11
-import { NavItem } from './NavItem'
12
-
13
-
14
-export function MainListItems(props){
15
-
16
-    const [open, setOpen] = React.useState(false);
17
-
18
-    const showPruebas = () => {
19
-        if(!props.AppBarVisible){
20
-            props.setAppBarVisible(true);
21
-        }
22
-        setOpen(!open);
23
-    };
24
-
25
-    return(
26
-        <List>
27
-
28
-            <ListSubheader inset>MENÚ</ListSubheader>
29
-
30
-            <NavItem icon={<Home/>} title="Inicio" route="home" />
31
-            <NavItem icon={<Work/>} title="Puestos" route="puestos" />
32
-            <NavItem icon={<VisibilityOff/>} title="Contraseñas" route="contrasenas" />
33
-            <NavItem icon={<PeopleAlt/>}  title="Expedientes" route="expedientes" />
34
-            <NavItem icon={<Equalizer/>} title="Resultados" route="resultados" />
35
-
36
-            <ListItem selected={open} onClick={showPruebas}>
37
-                <ListItemIcon>
38
-                    <Fingerprint />
39
-                </ListItemIcon>
40
-
41
-
42
-                <ListItemText 
43
-                    sx={{
44
-                        fontSize: 12,
45
-                        ' .css-10hburv-MuiTypography-root' : {
46
-                            fontSize : '.875rem'
47
-                        },
48
-                    }}
49
-                    primary="Pruebas" 
50
-                />
51
-                {open ? <ExpandLess /> : <ExpandMore />}
52
-            </ListItem>
53
-
54
-
55
-            <Collapse in={open} timeout="auto" unmountOnExit>
56
-                <List component="div" disablePadding>
57
-
58
-                    <NavItem setOpen={setOpen} { ...props} open={open} route="pruebas/crear" title="Crear Prueba" />
59
-                    <NavItem setOpen={setOpen} { ...props} open={open} route="pruebas/listar"  title="Listado de pruebas" />
60
-                    <NavItem setOpen={setOpen} { ...props} open={open} route="pruebas/aplicar"  title="Aplicar" />
61
-                    <NavItem setOpen={setOpen} { ...props} open={open} route="pruebas/respuestas" title="Respuestas" />
62
-                    <NavItem setOpen={setOpen} { ...props} open={open} route="pruebas/calificaciones" title="Calificaciones" />
63
-
64
-                </List>
65
-            </Collapse>
66
-
67
-            <NavItem icon={<MiscellaneousServices/>} title="Configuraciones" route="configuraciones" />
68
-            <NavItem icon={<History/>} title="Historial" route="historial" />
69
-        </List>
70
-    )
71
-}

+ 8 - 8
src/Components/Puestos/Card.jsx

@@ -10,8 +10,8 @@ import QA from '../../Images/puesto.jpg'
10 10
 
11 11
 export function PuestoCard(props) {
12 12
 
13
-    let { nombrepuesto, notas} = props.plaza
14
-    let {edit, suprime, show, set} = props.operations
13
+    let { plaza } = props
14
+    let { nombrepuesto, notas } = plaza
15 15
 
16 16
     return (
17 17
         <Card sx={{ maxWidth: 345 }}>
@@ -20,7 +20,7 @@ export function PuestoCard(props) {
20 20
                 alt="green iguana"
21 21
                 height="140"
22 22
                 image={QA}
23
-                />
23
+            />
24 24
             <CardContent>
25 25
                 <Typography gutterBottom variant="h5" component="div">
26 26
                     {nombrepuesto}
@@ -32,16 +32,16 @@ export function PuestoCard(props) {
32 32
                 </Typography>
33 33
             </CardContent>
34 34
             <CardActions>
35
-                <Button size="small" 
36
-                    onClick={() => [set,show].map(fnc => fnc(props.plaza)) }>
35
+                <Button size="small"
36
+                    onClick={() => props.toggle("VER", plaza)}>
37 37
                     Ver
38 38
                 </Button>
39
-                <Button size="small" 
40
-                    onClick={() => [set,edit].map(fnc => fnc(props.plaza))}>
39
+                <Button size="small"
40
+                    onClick={() => props.toggle("EDIT",plaza)}>
41 41
                     Editar
42 42
                 </Button>
43 43
                 <Button size="small"
44
-                    onClick={() =>[set,suprime].map(fnc => fnc(props.plaza))} >
44
+                    onClick={() => props.toggle("DEL", plaza)} >
45 45
                     Eliminar
46 46
                 </Button>
47 47
             </CardActions>

+ 2 - 11
src/Components/Puestos/GridMode.jsx

@@ -5,14 +5,7 @@ import { PuestoCard } from './Card';
5 5
 
6 6
 export function GridMode(props) {
7 7
 
8
-    let { setPuesto, setEdit, setDelete, setShow, data, index, showing } = props;
9
-
10
-    const op = {
11
-        set: setPuesto,
12
-        edit: setEdit,
13
-        suprime: setDelete,
14
-        show: setShow,
15
-    }
8
+    let { data, index, showing, toggle } = props;
16 9
 
17 10
     return (
18 11
         <React.Fragment>
@@ -23,9 +16,7 @@ export function GridMode(props) {
23 16
                             <Grow in={true} style={{ transformOrigin: '0 0 0' }} timeout={500} key={plaza.id} >
24 17
                                 <Col lg="4" md="6" sm="6" xs="12" >
25 18
                                     <div style={{ padding: 15 }}>
26
-                                        <PuestoCard
27
-                                            plaza={plaza}
28
-                                            operations={op} />
19
+                                        <PuestoCard toggle={toggle} plaza={plaza} />
29 20
                                     </div>
30 21
                                 </Col>
31 22
                             </Grow>

+ 24 - 13
src/Pages/Puestos.jsx

@@ -1,4 +1,4 @@
1
-import React, { useState, useCallback } from 'react';
1
+import React, { useState, useCallback} from 'react';
2 2
 import { Row, Col } from 'react-bootstrap'
3 3
 
4 4
 import { Toaster } from 'react-hot-toast';
@@ -32,6 +32,7 @@ import { ErrorMessage } from '../Components/Generics/Error'
32 32
 import { useQuery } from 'react-query';
33 33
 
34 34
 export function Puestos() {
35
+    console.log("render puestos")
35 36
 
36 37
     const auth = useAuth();
37 38
     const token = auth.getToken();
@@ -63,13 +64,30 @@ export function Puestos() {
63 64
         exclusive: true,
64 65
     };
65 66
 
66
-    let [puesto, setPuesto] = React.useState(false);
67 67
     let [manual, setManual] = React.useState(false);
68 68
     let [expres, setExpress] = React.useState(false);
69
+
70
+    let [puesto, setPuesto] = React.useState(false);
69 71
     let [edit, setEdit] = React.useState(false);
70 72
     let [del, setDelete] = React.useState(false);
71 73
     let [show, setShow] = React.useState(false);
72 74
 
75
+    const toggle = useCallback((type,puesto) => {
76
+        setPuesto(puesto)
77
+        switch(type){
78
+            case "VER": {
79
+                setShow(!show);
80
+                break;
81
+            }
82
+            case "EDIT": {
83
+                setEdit(!edit)
84
+                break;
85
+            }
86
+            default: break;
87
+        }
88
+        console.table(edit,del,show)
89
+    },[edit,del,show])
90
+
73 91
     if (isLoading){
74 92
         return(
75 93
             <Paper sx={{ mb: 2, padding: 2, height: '100%', minHeight: '95vh' }}>
@@ -126,13 +144,10 @@ export function Puestos() {
126 144
                             <div className={`main_productos ${alignment === 'grid' ? 'activar_vista' : 'desactivar_vista'}`} id="grid_view">
127 145
                                 <Row>
128 146
                                     <GridMode
147
+                                        toggle={toggle}
129 148
                                         showing={alignment}
130 149
                                         data={Divide( result.data )}
131 150
                                         index={page - 1}
132
-                                        setPuesto={setPuesto}
133
-                                        setEdit={setEdit}
134
-                                        setDelete={setDelete}
135
-                                        setShow={setShow}
136 151
                                     />
137 152
                                 </Row>
138 153
                             </div>
@@ -142,10 +157,6 @@ export function Puestos() {
142 157
                                         showing={alignment}
143 158
                                         data={Divide( result.data )}
144 159
                                         index={page - 1}
145
-                                        setPuesto={setPuesto}
146
-                                        setEdit={setEdit}
147
-                                        setDelete={setDelete}
148
-                                        setShow={setShow}
149 160
                                     />
150 161
                                 </Row>
151 162
                             </div>
@@ -172,9 +183,9 @@ export function Puestos() {
172 183
             <Express setExpress={setExpress} visible={expres} onClose={() => setExpress(false)} />
173 184
             <Manual visible={manual} onClose={() => setManual(false)} />
174 185
 
175
-            <Editar puesto={puesto} visible={edit} onClose={() => setEdit(false)} />
176
-            <Eliminar puesto={puesto} visible={del} onClose={() => setDelete(false)} />
177
-            <Mostrar puesto={puesto} visible={show} onClose={() => setShow(false)} />
186
+            <Mostrar puesto={puesto} visible={show} toggle={toggle} />
187
+            <Editar  puesto={puesto} visible={edit} toggle={toggle} />
188
+            <Eliminar visible={del} onClose={() => setDelete(false)} />
178 189
 
179 190
             <Toaster position="bottom-right" reverseOrder={false} />
180 191
 

+ 68 - 42
src/Utils/HTTP.js

@@ -2,16 +2,16 @@ import axios from 'axios';
2 2
 
3 3
 export class Service {
4 4
 
5
-    constructor(path){
5
+    constructor(path) {
6 6
         this.base_url = 'http://204.48.25.93:8081'
7
-        this.url =  this.base_url + path
7
+        this.url = this.base_url + path
8 8
         // this.base_url = 'http://psicoadmin.ditca.org:8081'
9 9
         // this.api =  'http://204.48.25.93:8081/user?user=patrik&password=12345'
10 10
         // this.api =  'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345'
11 11
     }
12 12
 
13 13
 
14
-    async getQuery(token){
14
+    async getQuery(token) {
15 15
         return await axios.get(this.url, {
16 16
             headers: {
17 17
                 'Authorization': `Bearer ${token}`
@@ -19,111 +19,137 @@ export class Service {
19 19
         })
20 20
     }
21 21
 
22
-    async get(token){
22
+    async get(token) {
23 23
         return axios.get(this.url, {
24 24
             headers: {
25 25
                 'Authorization': `Bearer ${token}`
26 26
             }
27 27
         })
28
-        .then((res) => {
29
-            return res;
30
-        })
31
-        .catch((error) => {
32
-            console.log("ERROR :: ", error)
33
-            return new Error("GG");
34
-        })
28
+            .then((res) => {
29
+                return res;
30
+            })
31
+            .catch((error) => {
32
+                console.log("ERROR :: ", error)
33
+                return new Error("GG");
34
+            })
35 35
     }
36 36
 
37
-    async post(body, token){
37
+    async post(body, token) {
38 38
 
39
-        if(!token){
39
+        if (!token) {
40 40
             let response = await axios({
41 41
                 method: "POST",
42 42
                 url: this.url,
43
-                headers:{
43
+                headers: {
44 44
                     'Content-Type': 'application/json',
45 45
                 },
46
-                data :body
46
+                data: body
47 47
             })
48
-            return await response.data; 
48
+            return await response.data;
49 49
         }
50 50
 
51 51
 
52
-        const MyHeaders ={
53
-            'Authorization': 'Bearer '+ token,
52
+        const MyHeaders = {
53
+            'Authorization': 'Bearer ' + token,
54 54
         }
55
-        
55
+
56 56
         let response = await axios({
57 57
             method: "POST",
58
-            url : this.url,
58
+            url: this.url,
59 59
             headers: MyHeaders,
60 60
             data: body
61 61
         })
62 62
         console.log('response', response)
63 63
 
64
-        return await response.data; 
64
+        return await response.data;
65 65
 
66 66
     }
67
-    
68
-    async postQuery(body, token){
69 67
 
70
-        if(!token){
68
+    async postQuery(body, token) {
69
+
70
+        if (!token) {
71 71
             return await axios({
72 72
                 method: "POST",
73 73
                 url: this.url,
74
-                headers:{
74
+                headers: {
75 75
                     'Content-Type': 'application/json',
76 76
                 },
77
-                data :body
77
+                data: body
78 78
             })
79 79
         }
80 80
 
81 81
 
82
-        const MyHeaders ={
83
-            'Authorization': 'Bearer '+ token,
82
+        const MyHeaders = {
83
+            'Authorization': 'Bearer ' + token,
84 84
         }
85
-        
85
+
86 86
         return await axios({
87 87
             method: "POST",
88
-            url : this.url,
88
+            url: this.url,
89 89
             headers: MyHeaders,
90 90
             data: body
91 91
         })
92 92
 
93 93
 
94 94
     }
95
-    
96
-    async put(body, token){
97 95
 
98
-        if(!token){
96
+    async put(body, token) {
97
+
98
+        if (!token) {
99 99
             let response = await axios({
100 100
                 method: "PUT",
101 101
                 url: this.url,
102
-                headers:{
102
+                headers: {
103 103
                     'Content-Type': 'application/json',
104 104
                 },
105
-                data :body
105
+                data: body
106 106
             })
107
-            return await response.data; 
107
+            return await response.data;
108 108
         }
109 109
 
110 110
 
111
-        const MyHeaders ={
112
-            'Authorization': 'Bearer '+ token,
111
+        const MyHeaders = {
112
+            'Authorization': 'Bearer ' + token,
113 113
         }
114
-        
114
+
115 115
         let response = await axios({
116 116
             method: "PUT",
117
-            url : this.url,
117
+            url: this.url,
118 118
             headers: MyHeaders,
119 119
             data: body
120 120
         })
121 121
         console.log('response', response)
122 122
 
123
-        return await response.data; 
123
+        return await response.data;
124 124
 
125 125
     }
126 126
 
127
-s 
127
+
128
+    async putQuery(body, token) {
129
+        if (!token) {
130
+            return await axios({
131
+                method: "PUT",
132
+                url: this.url,
133
+                headers: {
134
+                    'Content-Type': 'application/json',
135
+                },
136
+                data: body
137
+            })
138
+        }
139
+
140
+        const MyHeaders = {
141
+            'Authorization': 'Bearer ' + token,
142
+        }
143
+
144
+        return await axios({
145
+            method: "PUT",
146
+            url: this.url,
147
+            headers: MyHeaders,
148
+            data: body
149
+        })
150
+    }
151
+
152
+
153
+
128 154
 }
129 155