Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function CarService() {
if (CarService._instance) {
throw new Error("Use CarService.getInstance() instead of new.");
}
this._cars = [];
this._carsStore = Kinvey.DataStore.collection("cars");
CarService._instance = this;
this.load = function () {
return this._login().then(() => this._carsStore.sync()).then(() => {
const sortByNameQuery = new Kinvey.Query();
sortByNameQuery.ascending("name");
const stream = this._carsStore.find(sortByNameQuery);
return stream.toPromise();
}).then((data) => {
this._allCars = [];
data.forEach((carData) => {
carData.id = carData._id;
const car = new Car(carData);