mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 01:22:54 +00:00
feat: add catalog module
This commit is contained in:
committed by
Jovan Krunić
parent
e628f396e2
commit
03084b1c96
122
src/app/modules/catalog/catalog.provider.ts
Normal file
122
src/app/modules/catalog/catalog.provider.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {
|
||||
SCCatalogWithoutReferences,
|
||||
SCSearchFilter,
|
||||
SCSearchResponse,
|
||||
SCSemester,
|
||||
SCThingType,
|
||||
} from '@openstapps/core';
|
||||
import {DataProvider} from '../data/data.provider';
|
||||
/**
|
||||
* Service for providing catalog and semester data
|
||||
*/
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CatalogProvider {
|
||||
constructor(private readonly dataProvider: DataProvider) {}
|
||||
|
||||
/**
|
||||
* Get news messages
|
||||
* TODO: make dates sortable on the backend side and then adjust this method
|
||||
*
|
||||
* @param offset TODO
|
||||
* @param superCatalog TODO
|
||||
* @param semesterUID TODO
|
||||
*/
|
||||
async getCatalogsWith(
|
||||
offset?: number,
|
||||
superCatalog?: SCCatalogWithoutReferences,
|
||||
semesterUID?: string,
|
||||
): Promise<SCSearchResponse> {
|
||||
const filters: SCSearchFilter[] = [
|
||||
{
|
||||
type: 'value',
|
||||
arguments: {
|
||||
field: 'type',
|
||||
value: 'catalog',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (typeof semesterUID === 'string') {
|
||||
filters.push({
|
||||
type: 'value',
|
||||
arguments: {
|
||||
field: 'academicTerm.uid',
|
||||
value: semesterUID,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof superCatalog?.uid === 'string') {
|
||||
filters.push({
|
||||
type: 'value',
|
||||
arguments: {
|
||||
field: 'superCatalog.uid',
|
||||
value: superCatalog.uid,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
filters.push({
|
||||
type: 'value',
|
||||
arguments: {
|
||||
field: 'level',
|
||||
value: '0',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return this.dataProvider.search({
|
||||
filter: {
|
||||
arguments: {
|
||||
operation: 'and',
|
||||
filters: filters,
|
||||
},
|
||||
type: 'boolean',
|
||||
},
|
||||
size: 40,
|
||||
from: offset,
|
||||
sort: [
|
||||
{
|
||||
type: 'ducet',
|
||||
order: 'asc',
|
||||
arguments: {
|
||||
field: 'name',
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
async getRelevantSemesters(): Promise<SCSemester[]> {
|
||||
const response = await this.dataProvider.search({
|
||||
filter: {
|
||||
arguments: {
|
||||
field: 'type',
|
||||
value: SCThingType.Semester,
|
||||
},
|
||||
type: 'value',
|
||||
},
|
||||
size: 10,
|
||||
});
|
||||
|
||||
return (response.data as SCSemester[]).sort((a, b) =>
|
||||
b.startDate.localeCompare(a.startDate, 'en'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user