This commit is contained in:
2023-09-29 17:10:01 +00:00
parent fd2168492b
commit 6d0556cc6f
3 changed files with 289 additions and 7 deletions

50
js/puestos.js Normal file
View File

@@ -0,0 +1,50 @@
import { createApp } from 'https://unpkg.com/petite-vue?module';
const app = createApp({
message: null,
puestos: [],
carreras: [],
materias: [],
usuarios: [],
async nuevoPuesto(nuevoPuesto) {
try {
const res = await fetch('action/puesto.php', {
method: 'POST',
body: JSON.stringify({
puesto_nombre: nuevoPuesto
})
});
const data = await res.json();
this.puestos.push(data);
}
catch (error) {
alert(`Error: ${error}`);
}
},
async actualizarPuesto(puesto_id, materias, usuario_id) {
try {
const res = await fetch('action/puesto.php', {
method: 'PUT',
body: JSON.stringify({
puesto_id,
materias: materias.map(m => m.materia_id),
usuario_id
})
});
const data = await res.json();
this.message = data.msg;
// after 3 seconds, remove the message
setTimeout(() => {
this.message = null;
}, 3000);
}
catch (error) {
alert(`Error: ${error}`);
}
},
async mounted() {
this.puestos = await fetch('action/puesto.php').then(res => res.json());
this.carreras = await fetch('action/action_carreras.php').then(res => res.json());
this.materias = await fetch('action/action_materias.php').then(res => res.json());
this.usuarios = await fetch('action/usuarios.php').then(res => res.json());
}
}).mount('#app');