Comparing version
@@ -65,3 +65,3 @@ import { __extends } from "tslib"; | ||
isPublic: this.isPublic, | ||
categories: Array.from(this.categories.cache.keys()), | ||
categories: this.categories.cache.map(function (c) { return c.getIri(); }), | ||
}; | ||
@@ -68,0 +68,0 @@ }; |
@@ -13,3 +13,3 @@ import User from "./User"; | ||
/** Last update */ | ||
updatedAt: Date | null; | ||
updatedAt: Date; | ||
/** User who intervened */ | ||
@@ -16,0 +16,0 @@ moderator: User | null; |
@@ -12,3 +12,3 @@ import { __extends } from "tslib"; | ||
_this.state = data.state; | ||
_this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null; | ||
_this.updatedAt = new Date(data.updatedAt); | ||
_this.moderator = _this.getModerator((_a = data.moderator) === null || _a === void 0 ? void 0 : _a.id); | ||
@@ -15,0 +15,0 @@ _this.resource = ((_b = data.resource) === null || _b === void 0 ? void 0 : _b.id) ? (_c = _this.client.resources.cache.get(data.resource.id)) !== null && _c !== void 0 ? _c : null : null; |
@@ -12,2 +12,3 @@ import { Collection } from "@discordjs/collection"; | ||
constructor(client: Client); | ||
getValidateResources(): Collection<string, Resource>; | ||
/** Fetch all existing resources from the api */ | ||
@@ -14,0 +15,0 @@ fetchAll(): Promise<Collection<string, Resource>>; |
@@ -5,2 +5,3 @@ import { __awaiter, __extends, __generator } from "tslib"; | ||
import Resource from "../class/Resource"; | ||
import { APIValidationState } from "../@types"; | ||
/** Resource manager which allow to manipulate | ||
@@ -15,2 +16,7 @@ * the resources in the api */ | ||
} | ||
ResourceManager.prototype.getValidateResources = function () { | ||
return this.cache.filter(function (r) { | ||
return r.validations.getLastValidationState().state === APIValidationState.Validated; | ||
}); | ||
}; | ||
/** Fetch all existing resources from the api */ | ||
@@ -17,0 +23,0 @@ ResourceManager.prototype.fetchAll = function () { |
@@ -12,2 +12,6 @@ import Resource from "../class/Resource"; | ||
constructor(resource: Resource); | ||
/** Refresh this cache */ | ||
refresh(): void; | ||
/** Get last validation state */ | ||
getLastValidationState(): ValidationState; | ||
/** Create a new validation state for this resource */ | ||
@@ -14,0 +18,0 @@ create(validation: ValidationStateBuilder): Promise<Resource>; |
import { __awaiter, __extends, __generator } from "tslib"; | ||
import BaseManager from "./BaseManager"; | ||
import { Collection } from "@discordjs/collection"; | ||
var ResourceValidationStateManager = /** @class */ (function (_super) { | ||
@@ -8,5 +9,24 @@ __extends(ResourceValidationStateManager, _super); | ||
_this.resource = resource; | ||
_this.cache = _this.resource.client.validations.cache.filter(function (v) { var _a; return ((_a = v.resource) === null || _a === void 0 ? void 0 : _a.id) === _this.resource.id; }); | ||
_this.cache = new Collection(); | ||
_this.refresh(); | ||
return _this; | ||
} | ||
/** Refresh this cache */ | ||
ResourceValidationStateManager.prototype.refresh = function () { | ||
for (var _i = 0, _a = this.resource.data.validationStates; _i < _a.length; _i++) { | ||
var c = _a[_i]; | ||
var validationState = this.client.validations.cache.get(c.id); | ||
if (validationState) { | ||
this.cache.set(validationState.id, validationState); | ||
} | ||
} | ||
}; | ||
/** Get last validation state */ | ||
ResourceValidationStateManager.prototype.getLastValidationState = function () { | ||
var defaultArray = Array.from(this.cache.values()); | ||
var sortByDate = defaultArray.sort(function (v1, v2) { | ||
return v2.updatedAt.getTime() - v1.updatedAt.getTime(); | ||
}); | ||
return sortByDate[0]; | ||
}; | ||
/** Create a new validation state for this resource */ | ||
@@ -13,0 +33,0 @@ ResourceValidationStateManager.prototype.create = function (validation) { |
{ | ||
"name": "rr-apilib", | ||
"version": "0.4.0-alpha", | ||
"version": "0.5.0-alpha", | ||
"description": "Library for interact with RR-API", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
168508
1.19%2406
1.31%