@ngageoint/mage.sftp.service
Version:
The SFTP service package is a MAGE server plugin that sends observations to and SFTP location on create and update.
71 lines • 3.63 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.MongooseSftpObservationRepository = exports.SftpObservationModel = exports.SftpStatus = void 0;
const mongoose_1 = __importDefault(require("mongoose"));
var SftpStatus;
(function (SftpStatus) {
SftpStatus["SUCCESS"] = "SUCCESS";
SftpStatus["FAILED"] = "FAILED";
SftpStatus["PENDING"] = "PENDING";
})(SftpStatus = exports.SftpStatus || (exports.SftpStatus = {}));
const SftpObservationsSchema = new mongoose_1.default.Schema({
eventId: { type: Number, required: true, unique: true },
observationId: { type: String, required: true },
status: { type: String, enum: Object.values(SftpStatus), required: true }
}, {
timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' }
});
const SftpObservationModelName = 'SftpObservation';
function SftpObservationModel(connection, collectionName) {
return connection.model(SftpObservationModelName, SftpObservationsSchema, collectionName);
}
exports.SftpObservationModel = SftpObservationModel;
class MongooseSftpObservationRepository {
constructor(model) {
this.model = model;
}
findAll(eventId) {
return __awaiter(this, void 0, void 0, function* () {
const documents = yield this.model.find({ eventId: eventId });
return documents.map(document => document.toJSON());
});
}
findAllByStatus(eventId, status) {
return __awaiter(this, void 0, void 0, function* () {
const documents = yield this.model.find({ eventId: eventId, status: { $in: status } });
return documents.map(document => document.toJSON());
});
}
findLatest(eventId) {
return __awaiter(this, void 0, void 0, function* () {
const document = yield this.model.findOne({ eventId: eventId }, { updatedAt: true }, { sort: { updatedAt: -1 }, limit: 1 });
return document ? document.toJSON() : null;
});
}
isProcessed(eventId, observationId) {
return __awaiter(this, void 0, void 0, function* () {
const document = yield this.model.findOne({ eventId: eventId, observationId: observationId, status: SftpStatus.SUCCESS }, { limit: 1 });
return document !== null;
});
}
postStatus(eventId, observationId, status) {
return __awaiter(this, void 0, void 0, function* () {
const document = yield this.model.findOneAndUpdate({ eventId: eventId, observationId: observationId }, { eventId: eventId, observationId: observationId, status: status }, { upsert: true });
return document ? document.toJSON() : null;
});
}
}
exports.MongooseSftpObservationRepository = MongooseSftpObservationRepository;
//# sourceMappingURL=adapters.sftp.mongoose.js.map