• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GrottoCenter / grottocenter-api / 16128436743

07 Jul 2025 09:37PM UTC coverage: 42.622% (-2.6%) from 45.21%
16128436743

push

github

bsoufflet
feat(api): add marc record services and controller

  - add GET /api/v1/bibliographicMetadata/:id/format/:format
    - :format -> marcFormat-country
    - marcFormat can be 'unimarc' or 'marc21'
    - country can be 'it' or 'default' (if not specify, set to'default')
  - add policies in policies.js
  - add services in services/BibliographicMetadataService.js (getformat)
  - add services in services/MarcConvertor.js
  - add convertors format and country specification
  - Marc class to handle MARC records fields and subfields

729 of 2424 branches covered (30.07%)

Branch coverage included in aggregate %.

25 of 302 new or added lines in 9 files covered. (8.28%)

2486 of 5119 relevant lines covered (48.56%)

4.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.92
/api/services/MarcConvertorService.js
1
const defaultConvertor = require('./marcConvertor/country/Default');
1✔
2
const ItConvertor = require('./marcConvertor/country/It');
1✔
3
const Marc21Convertor = require('./marcConvertor/format/Marc21');
1✔
4
const UnimarcConvertor = require('./marcConvertor/format/Unimarc');
1✔
5

6
const MarcCountryTransformers = {
1✔
7
  default: defaultConvertor,
8
  it: ItConvertor,
9
};
10

11
const MarcFormatTransformers = {
1✔
12
  marc21: Marc21Convertor,
13
  unimarc: UnimarcConvertor,
14
};
15

16
module.exports = {
1✔
17
  /**
18
   * Converts a document to MARC format based on the specified format and country.
19
   * @param {Object} document - The document to convert (OAI Metadata).
20
   * @param {string} format - The MARC format to convert to (e.g., 'marc21', 'unimarc').
21
   * @param {string} country - The country code for the MARC transformation (e.g., 'it', 'default').
22
   * @return {Promise<string>} - A promise that resolves to the MARC record in ISO 2709 format.
23
   */
24
  documentToMarc: async (document, format, country) => {
NEW
25
    if (!MarcFormatTransformers[format]) {
×
NEW
26
      throw new Error(`Unsupported format: ${format}`);
×
27
    }
28

29
    // verify if country exist, if not exist take the default controller
NEW
30
    let selectedCountry = country || 'default';
×
NEW
31
    if (!MarcCountryTransformers[selectedCountry]) {
×
NEW
32
      selectedCountry = 'default';
×
33
    }
34

NEW
35
    const marcCountryModule = MarcCountryTransformers[selectedCountry];
×
NEW
36
    const marcFormatModule = MarcFormatTransformers[format];
×
37

38
    // Normalize the document using the country-specific transformer
NEW
39
    const normalizedData = await marcCountryModule.normalizeMarc(document);
×
40

41
    // Convert the normalized data to MARC using the specified format transformer
NEW
42
    const marcData = await marcFormatModule.transform(normalizedData);
×
43

44
    // Convert the data to ISO 2709 format
NEW
45
    const record = await marcData.transformDocumentToIso2709();
×
NEW
46
    return [record, selectedCountry];
×
47
  },
48

49
  /**
50
   * Returns the list of supported countries for MARC transformations.
51
   * @return {Array<string>} - An array of country codes supported for MARC transformations
52
   */
NEW
53
  getSupportedCountries: () => Object.keys(MarcCountryTransformers),
×
54

55
  /**
56
   * Returns the list of supported formats for MARC transformations.
57
   * @return {Array<string>} - An array of format names supported for MARC transformations
58
   */
NEW
59
  getSupportedFormats: () => Object.keys(MarcFormatTransformers),
×
60
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc