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

GrottoCenter / grottocenter-api / 15926998058

27 Jun 2025 01:02PM UTC coverage: 42.789% (-2.4%) from 45.194%
15926998058

push

github

YohannSchatt
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
    - getRecordFormat(id, format, country) -> returns the MARC record
  - add convertors format and country specification
  - marcRecord class to handle MARC records fields and subfields

729 of 2389 branches covered (30.51%)

Branch coverage included in aggregate %.

28 of 312 new or added lines in 10 files covered. (8.97%)

2487 of 5127 relevant lines covered (48.51%)

4.11 hits per line

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

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

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

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

17
// Different type of conversion for marc's data
18
const OutputType = {
2✔
19
  marc: 'iso2709',
20
  xml: 'marcxml',
21
  marcEdit: 'mrk',
22
};
23

24
function transformDocumentToIso2709(marcData, typeOfOutput) {
NEW
25
  return new Promise((resolve, reject) => {
×
NEW
26
    const records = Array.isArray(marcData) ? marcData : [marcData];
×
27

NEW
28
    marc4js.transform(
×
29
      records,
30
      { toFormat: OutputType[typeOfOutput] },
31
      (err, data) => {
NEW
32
        if (err) {
×
NEW
33
          reject(err);
×
NEW
34
          return;
×
35
        }
NEW
36
        resolve(data);
×
37
      }
38
    );
39
  });
40
}
41

42
module.exports = {
2✔
43
  /**
44
   * Converts a document to MARC format based on the specified format and country.
45
   * @param {Object} document - The document to convert (OAI Metadata).
46
   * @param {string} format - The MARC format to convert to (e.g., 'marc21', 'unimarc').
47
   * @param {string} country - The country code for the MARC transformation (e.g., 'it', 'default').
48
   * @return {Promise<string>} - A promise that resolves to the MARC record in ISO 2709 format.
49
   */
50
  documentToMarc: async (document, format, country) => {
NEW
51
    if (!MarcFormatTransformers[format]) {
×
NEW
52
      throw new Error(`Unsupported format: ${format}`);
×
53
    }
54

55
    // verify if country exist, if not exist take the default controller
NEW
56
    let selectedCountry = country || 'default';
×
NEW
57
    if (!MarcCountryTransformers[selectedCountry]) {
×
NEW
58
      selectedCountry = 'default';
×
59
    }
60

NEW
61
    const marcCountryModule = MarcCountryTransformers[selectedCountry];
×
NEW
62
    const marcFormatModule = MarcFormatTransformers[format];
×
63

64
    // Normalize the document using the country-specific transformer
NEW
65
    const normalizedData = await marcCountryModule.normalizeMarc(document);
×
66

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

70
    // Convert the data to ISO 2709 format
NEW
71
    const record = await transformDocumentToIso2709(marcData, 'marc');
×
NEW
72
    return [record, selectedCountry];
×
73
  },
74

75
  /**
76
   * Returns the list of supported countries for MARC transformations.
77
   * @return {Array<string>} - An array of country codes supported for MARC transformations
78
   */
NEW
79
  getSupportedCountries: () => Object.keys(MarcCountryTransformers),
×
80

81
  /**
82
   * Returns the list of supported formats for MARC transformations.
83
   * @return {Array<string>} - An array of format names supported for MARC transformations
84
   */
NEW
85
  getSupportedFormats: () => Object.keys(MarcFormatTransformers),
×
86
};
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