puestos.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { createApp } from 'https://unpkg.com/petite-vue?module';
  2. const app = createApp({
  3. message: null,
  4. puestos: [],
  5. carreras: [],
  6. materias: [],
  7. usuarios: [],
  8. async nuevoPuesto(nuevoPuesto) {
  9. try {
  10. const res = await fetch('action/puesto.php', {
  11. method: 'POST',
  12. body: JSON.stringify({
  13. puesto_nombre: nuevoPuesto
  14. })
  15. });
  16. const data = await res.json();
  17. this.puestos.push(data);
  18. }
  19. catch (error) {
  20. alert(`Error: ${error}`);
  21. }
  22. },
  23. async actualizarPuesto(puesto_id, materias, usuario_id) {
  24. try {
  25. const res = await fetch('action/puesto.php', {
  26. method: 'PUT',
  27. body: JSON.stringify({
  28. puesto_id,
  29. materias: materias.map(m => m.materia_id),
  30. usuario_id
  31. })
  32. });
  33. const data = await res.json();
  34. this.message = data.msg;
  35. // after 3 seconds, remove the message
  36. setTimeout(() => {
  37. this.message = null;
  38. }, 3000);
  39. }
  40. catch (error) {
  41. alert(`Error: ${error}`);
  42. }
  43. },
  44. async mounted() {
  45. this.puestos = await fetch('action/puesto.php').then(res => res.json());
  46. this.carreras = await fetch('action/action_carreras.php').then(res => res.json());
  47. this.materias = await fetch('action/action_materias.php').then(res => res.json());
  48. this.usuarios = await fetch('action/usuarios.php').then(res => res.json());
  49. }
  50. }).mount('#app');