bugyo-cloud-client
Version:
HTTP client for Bugyo Cloud
65 lines • 2.84 kB
JavaScript
;
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeClock = void 0;
const querystring_1 = __importDefault(require("querystring"));
const url_utils_1 = require("../utils/url-utils");
const base_endpoint_1 = require("./base/base-endpoint");
/**
* 打刻します。
*/
class TimeClock extends base_endpoint_1.BaseEndpoint {
invoke(client, token, punchInfo) {
return __awaiter(this, void 0, void 0, function* () {
const url = (0, url_utils_1.produceUrl)("TimeClock", client.param);
const config = this.createConfig(client, token);
const data = this.createData(punchInfo);
this.logger.debug("Trying to POST, url=%s", url, data, config);
const resp = yield client.session.post(url, data, config);
this.throwIfNgStatus(resp);
this.logger.info('TimeClock succeed.');
});
}
createConfig(client, token) {
return {
headers: this.createHeaders(client, token),
maxRedirects: 0,
};
}
createHeaders(client, token) {
return {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
Referer: this.getRefererUrl(client),
__RequestVerificationToken: token,
"X-Requested-With": "XMLHttpRequest",
};
}
getRefererUrl(client) {
return (0, url_utils_1.produceUrl)("PunchmarkPage", client.param);
}
createData(punchInfo) {
var _a, _b;
return querystring_1.default.stringify({
ClockType: punchInfo.clockType,
LaborSystemID: "0",
LaborSystemCode: "",
LaborSystemName: "",
PositionLatitude: (_a = punchInfo.latitude) !== null && _a !== void 0 ? _a : 0,
PositionLongitude: (_b = punchInfo.longitude) !== null && _b !== void 0 ? _b : 0,
PositionAccuracy: "0",
});
}
}
exports.TimeClock = TimeClock;
//# sourceMappingURL=time-clock.js.map