lecturers.ts 674 B

123456789101112131415161718192021222324252627282930
  1. import { defineStore } from "pinia";
  2. import { Lecturer } from "../api/types/lecturers";
  3. import { getLecturers } from "../api/modules/lecturers";
  4. export const useLecturersStore = defineStore("lecturers", {
  5. state: () => {
  6. return {
  7. data: [] as Lecturer[],
  8. };
  9. },
  10. actions: {
  11. fetchData() {
  12. getLecturers()
  13. .then((data) => {
  14. this.data = data;
  15. })
  16. .catch((error) => {
  17. console.error(error);
  18. this.data = [];
  19. });
  20. },
  21. fromShort(shorts: string[]): Lecturer[] {
  22. const r = this.data.filter((el) => {
  23. return shorts.includes(el.short);
  24. });
  25. return r;
  26. },
  27. },
  28. });