UNPKG

the-camp

Version:
77 lines 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TheCampClient = void 0; const types_1 = require("../core/types"); const the_camp_1 = require("../services/the-camp"); class TheCampClient { constructor(credential) { this.credential = credential; this.theCampService = new the_camp_1.TheCampService(); } async fetchSession() { if (!this.session) { this.session = await this.theCampService.login(this.credential); } return this.session; } async registerSoldier(soldierInfo) { const session = await this.fetchSession(); await this.theCampService.registerSoldier(soldierInfo, session); const soldiers = await this.theCampService.fetchSoldiers(session); for (const soldier of soldiers) { if (soldier.hasCafe) continue; await this.theCampService.registerCafe({ ...soldierInfo, 정렬번호: soldier.정렬번호, 입영부대TypeCode: soldier.입영부대TypeCode, }, session); } const cafeRegisteredSoldiers = await this.theCampService.fetchSoldiers(session); const soldier = cafeRegisteredSoldiers .filter((soldier) => soldier.hasCafe) .find((soldier) => { if (soldier.이름 !== soldierInfo.이름) { return false; } if (soldier.입영부대Code !== types_1.입영부대CodeMap[soldierInfo.입영부대]) { return false; } if (soldier.입영일 !== soldierInfo.입영일) { return false; } return true; }); if (!soldier || !soldier.hasCafe) { throw new Error('군인의 카페가 개설되지 않았습니다.'); } const [{ 훈련병Id }] = await this.theCampService.fetchUnitSoldiers({ 입영부대Code: soldier.입영부대Code, 입영부대EduId: soldier.입영부대EduId, }, session); const soldierId = this.createSoldierId({ 훈련병Id, 입영부대: soldierInfo.입영부대, 입영부대EduId: soldier.입영부대EduId, }); return { soldierId }; } async sendLetter(soldierId, letterInfo) { const soldierIdentifier = this.parseSoldierId(soldierId); const session = await this.fetchSession(); await this.theCampService.sendLetter({ ...soldierIdentifier, ...letterInfo }, session); } createSoldierId({ 입영부대, 입영부대EduId, 훈련병Id, }) { return `${입영부대}#${입영부대EduId}#${훈련병Id}`; } parseSoldierId(soldierId) { const [입영부대, 입영부대EduId, 훈련병Id] = soldierId.split('#'); return { 입영부대: 입영부대, 입영부대EduId, 훈련병Id, }; } } exports.TheCampClient = TheCampClient; //# sourceMappingURL=the-camp.client.js.map