addresses: filter out postal code introduced by user

This commit is contained in:
nobohan 2021-06-16 16:20:37 +02:00
parent 5b72eeb147
commit e2633a2a79
4 changed files with 71 additions and 5 deletions

View File

@ -54,6 +54,13 @@ class PostalCode
*/
private $country;
/**
* @var integer
*
* @ORM\Column(name="origin", type="integer", nullable=true)
* @groups({"write", "read"})
*/
private $origin = 0;
/**
* Get id
@ -65,6 +72,32 @@ class PostalCode
return $this->id;
}
/**
* Set origin
*
* @param int $origin
*
* @return PostalCode
*/
public function setOrigin($origin)
{
$this->origin = $origin;
return $this;
}
/**
* Get origin
*
* @return int
*/
public function getOrigin()
{
return $this->origin;
}
/**
* Set name
*

View File

@ -45,10 +45,12 @@ const store = createStore({
console.log('@A addAddress payload', payload);
if('newPostalCode' in payload){
postPostalCode(payload.newPostalCode)
let postalCodeBody = payload.newPostalCode;
postalCodeBody = Object.assign(postalCodeBody, {'origin': 3});
postPostalCode(postalCodeBody)
.then(postalCode => {
let body = payload;
body.postcode = {'id': postalCode.id },
body.postcode = {'id': postalCode.id},
postAddress(body)
.then(address => new Promise((resolve, reject) => {
commit('addAddress', address);
@ -95,7 +97,9 @@ const store = createStore({
console.log('@A updateAddress payload', payload);
if('newPostalCode' in payload.newAddress){ // TODO change the condition because it writes new postal code in edit mode now: !writeNewPostalCode
postPostalCode(payload.newAddress.newPostalCode)
let postalCodeBody = payload.newAddress.newPostalCode;
postalCodeBody = Object.assign(postalCodeBody, {'origin': 3});
postPostalCode(postalCodeBody)
.then(postalCode => {
let body = payload.newAddress;
body.postcode = {'id': postalCode.id },

View File

@ -181,8 +181,8 @@ export default {
getCities(country) {
console.log('getCities for', country.name);
fetchCities(country).then(cities => new Promise((resolve, reject) => {
this.address.loaded.cities = cities.results;
resolve()
this.address.loaded.cities = cities.results.filter(c => c.origin !== 3); // filter out user-defined cities
resolve();
}))
.catch((error) => {
this.errorMsg.push(error.message);

View File

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210616134328 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_postal_code ADD origin INT DEFAULT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_postal_code DROP origin');
}
}