phx-node
Version:
PHX NODE
62 lines • 3.8 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var PHXInternalParentService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PHXInternalParentService = void 0;
const common_1 = require("@nestjs/common");
const config_1 = require("@nestjs/config");
const axios_1 = require("@nestjs/axios");
let PHXInternalParentService = PHXInternalParentService_1 = class PHXInternalParentService {
constructor(configService, httpService) {
this.configService = configService;
this.httpService = httpService;
this.logger = new common_1.Logger(PHXInternalParentService_1.name);
}
/**
* Lấy danh sách học sinh (con) của phụ huynh theo số điện thoại từ các trường khác nhau.
* Gửi yêu cầu POST tới API nội bộ `/contacts/internal/parent/children` thông qua `INTERNAL_API_GATEWAY`.
*
* @param {string} phoneNumber - Số điện thoại của phụ huynh.
* @returns {Promise<{ data: { children: Array<{ id: number, full_name: string, user_code: string, school_id: number, school_name: string, class_name: string, avatar_url: string | null, educational_code: string, hostname: string }> } }>}
* Đối tượng chứa danh sách phẳng các học sinh, bao gồm thông tin chi tiết từng học sinh cùng thông tin trường học của học sinh đó.
*/
getParentChildrenByPhone(phoneNumber) {
return __awaiter(this, void 0, void 0, function* () {
const URL = this.configService.get("INTERNAL_API_GATEWAY");
const path = `${URL}/contacts/internal/parent/children`;
const payload = { phone_number: phoneNumber };
try {
const response = yield this.httpService.post(path, payload).toPromise();
return response.data;
}
catch (error) {
this.logger.error(`Failed to get parent children: ${error.message}`);
return { data: { children: [] } };
}
});
}
};
exports.PHXInternalParentService = PHXInternalParentService;
exports.PHXInternalParentService = PHXInternalParentService = PHXInternalParentService_1 = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [config_1.ConfigService,
axios_1.HttpService])
], PHXInternalParentService);
//# sourceMappingURL=internal-parent.service.js.map