Skip to content

Commit c0c75c2

Browse files
committed
split maintenance limitation
1 parent 04f437f commit c0c75c2

File tree

9 files changed

+215
-151
lines changed

9 files changed

+215
-151
lines changed

app.vue

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,28 @@
134134
Volveremos a la normalidad {{ SIAMaintenanceTillAt }}.
135135
</p>
136136
</div>
137+
<div
138+
v-else-if="
139+
APP.ExplorerV1Maintenance || APP.ExplorerV2Maintenance
140+
"
141+
class="txt --txtAlign-center --gap-10"
142+
>
143+
<h4>El buscador se encuentra en mantenimiento</h4>
144+
<p class="--txtSize-sm --txtColor-dark5">
145+
Puedes explorar los cursos previamente guardados.
146+
</p>
147+
<p
148+
v-if="APP.ExplorerV1Maintenance"
149+
class="--txtSize-xs --txtColor-dark5"
150+
>
151+
Volveremos a la normalidad
152+
{{ ExplorerV1MaintenanceTillAt }}.
153+
</p>
154+
<p v-else class="--txtSize-xs --txtColor-dark5">
155+
Volveremos a la normalidad
156+
{{ ExplorerV2MaintenanceTillAt }}.
157+
</p>
158+
</div>
137159
<div
138160
v-else-if="!SESSION.token && route.path != '/ingresar'"
139161
class="txt --txtAlign-center --gap-10"
@@ -176,6 +198,16 @@
176198
177199
return useTimeAgo(date);
178200
});
201+
const ExplorerV1MaintenanceTillAt = computed(() => {
202+
const date = new Date(APP.instance?.config?.explorerV1MaintenanceTillAt || new Date());
203+
204+
return useTimeAgo(date);
205+
});
206+
const ExplorerV2MaintenanceTillAt = computed(() => {
207+
const date = new Date(APP.instance?.config?.explorerV2MaintenanceTillAt || new Date());
208+
209+
return useTimeAgo(date);
210+
});
179211
180212
// lifecycle
181213
useHead(() => {

components/searchCourse.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
import type { CourseValues } from "~/resources/types/values";
128128
import {
129129
eSIATypology,
130-
type SIACoursesResponse,
130+
type CoursesResponse,
131131
type uSIAProgram,
132132
} from "~/functions/src/types/SIA";
133133
import { getDocumentId } from "~/resources/utils/firestore";
@@ -145,7 +145,7 @@
145145
const searchUntrackedRef = ref<HTMLElement>();
146146
const searching = ref(false);
147147
const errors = ref();
148-
const untrackedCurrentPage = ref<SIACoursesResponse>();
148+
const untrackedCurrentPage = ref<CoursesResponse<Course>>();
149149
const untrackedCourses = ref<Course[]>();
150150
const savedUntrackedCourses = ref<Record<number, Course[]>>({});
151151
const lastSearch = ref<CourseValues & { page?: number }>();
@@ -178,7 +178,7 @@
178178
errors.value = undefined;
179179
180180
try {
181-
const coursesPage = await useSIACourses(
181+
const coursesPage = await useExplorerV1Courses(
182182
props.values,
183183
untrackedCurrentPage.value?.currentPage
184184
);
@@ -189,9 +189,7 @@
189189
* Remove duplicates & omit courses without groups
190190
* The system return entities with the same data but differing in the internal id
191191
*/
192-
coursesPage.data.forEach((SIAcourse) => {
193-
const { faculties = [], ...course } = useMapCourseFromBETA(SIAcourse);
194-
192+
coursesPage.data.forEach(({ faculties = [], ...course }) => {
195193
if (!course.code || !course.groups?.length) return;
196194
197195
const dedupedCourseIndex = dedupedCourses.findIndex(({ id }) => id === course.id);
@@ -247,7 +245,7 @@
247245
/**
248246
* Index unindexed courses
249247
*/
250-
async function indexCourses(courses: Course[], page: SIACoursesResponse) {
248+
async function indexCourses(courses: Course[], page: CoursesResponse<Course>) {
251249
try {
252250
const include = courses.map(({ id }) => id);
253251
const indexedCoursesEdges = await useFetchQuery<iPageEdge<Course, string>[]>(

composables/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export function useMapGroupFromBETA(source: SIAGroup): Group {
231231
/**
232232
* Map course from SIA beta
233233
*/
234-
export function useMapCourseFromBETA(source: SIACourse): Course {
234+
export function useMapCourseFromExplorerV1(source: SIACourse): Course {
235235
// Generate deduped course UID
236236
const id = `courses/${Cyrb53([source.CODIGO_ASIGNATURA])}`;
237237
const groups: Group[] = [];

composables/sia.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { arrayUnion } from "firebase/firestore";
22

3-
import type { SIACoursesResponse } from "~/functions/src/types/SIA";
3+
import type { CoursesResponse, ExplorerV1CoursesResponse } from "~/functions/src/types/SIA";
44
import type { Course, CourseRef } from "~/resources/types/entities";
55
import type { CourseValues } from "~/resources/types/values";
66
import { triGram } from "~/resources/utils/firestore";
77

8-
export function useSIACourses(values: CourseValues, page = 1) {
8+
export async function useExplorerV1Courses(
9+
values: CourseValues,
10+
page = 1
11+
): Promise<CoursesResponse<Course>> {
912
const APP = useAppStore();
1013
const { siaCoursesURL = "", siaCoursesPath = "" } = APP.instance?.config || {};
1114
const coursesEndpoint = `${siaCoursesURL}${siaCoursesPath}`;
1215

13-
return useFetchQuery<SIACoursesResponse>(coursesEndpoint, {
16+
const response = await useFetchQuery<ExplorerV1CoursesResponse>(coursesEndpoint, {
1417
nivel: values.level,
1518
sede: values.place,
1619
planEstudio: values.program || undefined,
@@ -20,6 +23,8 @@ export function useSIACourses(values: CourseValues, page = 1) {
2023
limit: 30, // firebase compound limit
2124
page,
2225
});
26+
27+
return { ...response, data: response.data.map(useMapCourseFromExplorerV1) };
2328
}
2429

2530
export async function useIndexCourse(

composables/store/app.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ export const useAppStore = defineStore("app", {
3131

3232
if (!till) return false;
3333

34+
return till > new Date();
35+
},
36+
ExplorerV1Maintenance({ instance = {} }) {
37+
const till = instance?.config?.explorerV1MaintenanceTillAt;
38+
39+
if (!till) return false;
40+
41+
return till > new Date();
42+
},
43+
ExplorerV2Maintenance({ instance = {} }) {
44+
const till = instance?.config?.explorerV2MaintenanceTillAt;
45+
46+
if (!till) return false;
47+
3448
return till > new Date();
3549
},
3650
},

functions/src/types/SIA/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export interface SIACoursesPayload {
3737
limit?: number;
3838
}
3939

40-
export interface SIACoursesResponse {
41-
data: SIACourse[];
40+
export interface CoursesResponse<T> {
41+
data: T[];
4242
totalRecords: number;
4343
totalPages: number;
4444
currentPage: number;
@@ -47,3 +47,5 @@ export interface SIACoursesResponse {
4747
*/
4848
limit: number;
4949
}
50+
51+
export type ExplorerV1CoursesResponse = CoursesResponse<SIACourse>;

functions/src/types/entities.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ export interface InstanceConfig<T> {
7979
*/
8080
maintenanceMessage?: string;
8181
/**
82-
* SIA under maintenance till
82+
* Old SIA under maintenance till
8383
*/
8484
siaMaintenanceTillAt?: T;
85+
/**
86+
* Explorer V1 under maintenance till
87+
*/
88+
explorerV1MaintenanceTillAt?: T;
89+
/**
90+
* Explorer V2 under maintenance till
91+
*/
92+
explorerV2MaintenanceTillAt?: T;
8593
/**
8694
* @example https://bobt42d1b3.execute-api.us-east-1.amazonaws.com/api/v1
8795
*/

0 commit comments

Comments
 (0)