@fabrix/spool-cart
Version:
Spool - eCommerce Spool for Fabrix
98 lines (97 loc) • 3.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@fabrix/fabrix/dist/common");
const errors_1 = require("@fabrix/spool-sequelize/dist/errors");
class CountryService extends common_1.FabrixService {
createCountry(country) {
return Promise.resolve(country);
}
updateCountry(country) {
return Promise.resolve(country);
}
destroyCountry(country) {
return Promise.resolve(country);
}
createProvince(province) {
return Promise.resolve(province);
}
updateProvince(province) {
return Promise.resolve(province);
}
destroyProvince(province) {
return Promise.resolve(province);
}
createCounty(county) {
return Promise.resolve(county);
}
updateCounty(county) {
return Promise.resolve(county);
}
destroyCounty(county) {
return Promise.resolve(county);
}
createCity(city) {
return Promise.resolve(city);
}
updateCity(city) {
return Promise.resolve(city);
}
destroyCity(city) {
return Promise.resolve(city);
}
addProvince(country, province) {
let resCountry, resProvince;
return this.app.models.Country.resolveCountry(country)
.then(_country => {
if (!_country) {
throw new errors_1.ModelError('E_NOT_FOUND', 'Country not found');
}
resCountry = _country;
return this.app.models.Province.resolveProvince(province);
})
.then(_province => {
if (!_province) {
throw new errors_1.ModelError('E_NOT_FOUND', 'Country not found');
}
resProvince = _province;
return resCountry.hasProvince(resProvince.id);
})
.then(hasProvince => {
if (!hasProvince) {
return resCountry.addProvince(resProvince.id);
}
return resCountry;
})
.then(_province => {
return this.app.models['Country'].findById(resCountry.id);
});
}
removeProvince(country, province) {
let resCountry, resProvince;
return this.app.models.Country.resolveCountry(country)
.then(_country => {
if (!_country) {
throw new errors_1.ModelError('E_NOT_FOUND', 'Country not found');
}
resCountry = _country;
return this.app.models.Province.resolveProvince(province);
})
.then(_province => {
if (!_province) {
throw new errors_1.ModelError('E_NOT_FOUND', 'Country not found');
}
resProvince = _province;
return resCountry.hasProvince(resProvince.id);
})
.then(hasProvince => {
if (hasProvince) {
return resCountry.removeProvince(resProvince.id);
}
return resCountry;
})
.then(_province => {
return this.app.models['Country'].findById(resCountry.id);
});
}
}
exports.CountryService = CountryService;