diff --git a/api/main.bal b/api/main.bal index c514fa0..ec2454b 100644 --- a/api/main.bal +++ b/api/main.bal @@ -10,6 +10,27 @@ service graphql:Service /graphql on new graphql:Listener(4000) { return new (name, id); } + remote function add_address(Address address) returns AddressData|error? { + sql:ExecutionResult res = check db_client->execute( + `INSERT INTO avinya_db.address ( + street_address, + phone, + city_id + ) VALUES ( + ${address.street_address}, + ${address.phone}, + ${address.city_id} + );` + ); + + int|string? insert_id = res.lastInsertId; + if !(insert_id is int) { + return error("Unable to insert addresss"); + } + + return new(insert_id); + } + remote function add_organization(Organization org) returns OrganizationData|error? { sql:ExecutionResult res = check db_client->execute( `INSERT INTO avinya_db.organization ( diff --git a/db/schema/1-base_data.sql b/db/schema/1-base_data.sql index e465aa7..a01c129 100644 --- a/db/schema/1-base_data.sql +++ b/db/schema/1-base_data.sql @@ -2,7 +2,7 @@ USE avinya_db; -- Insert Sri Lanka Province data -INSERT INTO province (id, name_en, name_si, name_ta) VALUES +INSERT IGNORE INTO province (id, name_en, name_si, name_ta) VALUES (1, 'Western', 'බස්නාහිර', 'மேல்'), (2, 'Central', 'මධ්‍යම', 'மத்திய'), (3, 'Southern', 'දකුණු', 'தென்'), @@ -15,7 +15,7 @@ INSERT INTO province (id, name_en, name_si, name_ta) VALUES -- Insert Sri Lanka District data -INSERT INTO district (id, province_id, name_en, name_si, name_ta) VALUES +INSERT IGNORE INTO district (id, province_id, name_en, name_si, name_ta) VALUES (1, 6, 'Ampara', 'අම්පාර', 'அம்பாறை'), (2, 8, 'Anuradhapura', 'අනුරාධපුරය', 'அனுராதபுரம்'), (3, 7, 'Badulla', 'බදුල්ල', 'பதுளை'), @@ -44,7 +44,7 @@ INSERT INTO district (id, province_id, name_en, name_si, name_ta) VALUES -- Insert Sri Lanka City data -INSERT INTO city (id, district_id, name_en, name_si, name_ta, suburb_name_en, suburb_name_si, suburb_name_ta, postcode, latitude, longitude) VALUES +INSERT IGNORE INTO city (id, district_id, name_en, name_si, name_ta, suburb_name_en, suburb_name_si, suburb_name_ta, postcode, latitude, longitude) VALUES (1, 1, 'Akkaraipattu', 'අක්කරපත්තුව', 'அக்கரைப்பற்று', NULL, NULL, NULL, '32400', '7.21842790', '81.85411610'), (2, 1, 'Ambagahawatta', 'අඹගහවත්ත', 'அம்பகஹவத்த', NULL, NULL, NULL, '90326', '7.30175630', '81.67472950'), (3, 1, 'Ampara', 'අම්පාර', 'அம்பாறை', NULL, NULL, NULL, '32000', '7.30175630', '81.67472950'), diff --git a/db/schema/2-organization_and_address_tables.sql b/db/schema/2-organization_and_address_tables.sql index 256fba0..3e4bd6b 100644 --- a/db/schema/2-organization_and_address_tables.sql +++ b/db/schema/2-organization_and_address_tables.sql @@ -3,9 +3,6 @@ USE avinya_db; -- Address CREATE TABLE IF NOT EXISTS address ( id INT NOT NULL PRIMARY KEY, - name_en VARCHAR(255) NOT NULL, - name_ta VARCHAR(255), - name_si VARCHAR(255), street_address VARCHAR(255) NOT NULL, phone INT, city_id INT NOT NULL, @@ -18,7 +15,7 @@ CREATE TABLE IF NOT EXISTS organization ( name_en VARCHAR(255) NOT NULL, name_ta VARCHAR(255), name_si VARCHAR(255), - phone int, + phone INT, address_id INT NOT NULL, FOREIGN KEY (address_id) REFERENCES address(id) ); diff --git a/db/schema/3-avinya_types.sql b/db/schema/3-avinya_types.sql new file mode 100644 index 0000000..4bf03ca --- /dev/null +++ b/db/schema/3-avinya_types.sql @@ -0,0 +1,27 @@ +USE avinya_db; + +CREATE TABLE IF NOT EXISTS avinya_type ( + id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + active BOOLEAN NOT NULL, + global_type ENUM("Employee", "Customer", "Volunteer", "Applicant", "Team") NOT NULL, + name VARCHAR(255), + foundation_type ENUM( + "Advisors", + "Educator", + "Technology", + "Operations", + "Parent", + "Student" + ), + focus ENUM( + "Bootcamp", + "Healthcare", + "Information Technology" + ), + level INT +); + +ALTER TABLE organization +ADD COLUMN avinya_type INT NOT NULL; +ALTER TABLE organization +ADD FOREIGN KEY (avinya_type) REFERENCES avinya_db.avinya_type(id);