forked from cemaden-educacao/WPD-MobileApp
Browse Source
Finishing an MVP from the SharingFloodZone screen with integration on MapFeedScreen.
master
Finishing an MVP from the SharingFloodZone screen with integration on MapFeedScreen.
master
GabrielTrettel
4 years ago
4 changed files with 263 additions and 208 deletions
-
36src/app/database/databaseLoader.js
-
296src/app/database/db.js
-
71src/app/screens/MapFeedScreen.js
-
18src/app/screens/SharingFloodZonesScreen.js
@ -0,0 +1,36 @@ |
|||||
|
import "../config/globals"; |
||||
|
|
||||
|
function transaction(db, query, values) { |
||||
|
db.transaction((tx) => { |
||||
|
tx.executeSql( |
||||
|
query, |
||||
|
values, |
||||
|
(_, results) => { |
||||
|
console.debug("Values inserted successfully" + results.rowsAffected); |
||||
|
}, |
||||
|
(_, err) => { |
||||
|
console.debug("Error while inserting values: " + JSON.stringify(err)); |
||||
|
} |
||||
|
); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function insertFloodZone({ images, description, passable, location }) { |
||||
|
const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable) VALUES(?, ?, ?, ?, ?);`; |
||||
|
if (location === undefined) { |
||||
|
console.debug("undefined location"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
const values = [ |
||||
|
description, |
||||
|
JSON.stringify(images), |
||||
|
parseFloat(location["latitude"]), |
||||
|
parseFloat(location["longitude"]), |
||||
|
parseInt(passable), |
||||
|
]; |
||||
|
|
||||
|
transaction(global.userDataBase, query, values); |
||||
|
} |
||||
|
|
||||
|
export default insertFloodZone; |
@ -1,149 +1,161 @@ |
|||||
const init_queries = [ |
|
||||
`CREATE TABLE IF NOT EXISTS Users (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Email text NOT NULL, |
|
||||
FirstName text NOT NULL, |
|
||||
SurName text NOT NULL, |
|
||||
Avatar text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Profiles (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Name text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS UsersProfiles (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdUsers integer NOT NULL, |
|
||||
IdProfiles integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdUsers) REFERENCES Users (Id), |
|
||||
FOREIGN KEY (IdProfiles) REFERENCES Profiles (Id) |
|
||||
);`,
|
|
||||
|
// FIXME: Refactor to our database ERM already combined
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Permissions (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Name text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS ProfilesPermissions (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdProfiles integer NOT NULL, |
|
||||
IdPermissions integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdProfiles) REFERENCES Profiles (Id), |
|
||||
FOREIGN KEY (IdPermissions) REFERENCES Permissions (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FormsOrigins (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Name text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Forms (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFormsOrigins integer NOT NULL, |
|
||||
Name text NOT NULL, |
|
||||
Description text NOT NULL, |
|
||||
DtCreation TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFormsOrigins) REFERENCES FormsOrigins (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FieldsDataTypes (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
Name text NOT NULL, |
|
||||
Description text NOT NULL, |
|
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Fields (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFieldsDataTypes integer NOT NULL, |
|
||||
Name text NOT NULL, |
|
||||
Description text NOT NULL, |
|
||||
FillingClue text NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFieldsDataTypes) REFERENCES FieldsDataTypes (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FormsFields (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdForms integer NOT NULL, |
|
||||
IdFields integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdForms) REFERENCES Forms (Id), |
|
||||
FOREIGN KEY (IdFields) REFERENCES Fields (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS Alternatives (
|
|
||||
|
const init_queries = [ |
||||
|
`CREATE TABLE IF NOT EXISTS FloodZones (
|
||||
Id integer PRIMARY KEY autoincrement, |
Id integer PRIMARY KEY autoincrement, |
||||
Response text NOT NULL, |
|
||||
ShortResponse text NOT NULL, |
|
||||
Description text NOT NULL, |
Description text NOT NULL, |
||||
Active integer NOT NULL |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FieldsAlternatives (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFields integer NOT NULL, |
|
||||
IdAlternatives integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFields) REFERENCES Fields (Id), |
|
||||
FOREIGN KEY (IdAlternatives) REFERENCES Alternatives (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS FieldsAnswers (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFields integer NOT NULL, |
|
||||
Value text NOT NULL, |
|
||||
DtFilling TIMESTAMP NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFields) REFERENCES Fields (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS UsersInformerFieldsAnswers (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdUsersInformer integer NOT NULL, |
|
||||
IdFieldsAnswers integer NOT NULL, |
|
||||
Latitude real NULL, |
|
||||
Longitude real NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdUsersInformer) REFERENCES Users (Id), |
|
||||
FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS UsersEndorsementFieldsAnswers (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdUsersEndorsement integer NOT NULL, |
|
||||
IdFieldsAnswers integer NOT NULL, |
|
||||
Latitude real NULL, |
|
||||
Longitude real NULL, |
|
||||
IsTrustable integer NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdUsersEndorsement) REFERENCES Users (Id), |
|
||||
FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS PreliminaryData (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFieldsAnswers integer NOT NULL, |
|
||||
DtInsert TIMESTAMP NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id) |
|
||||
);`,
|
|
||||
|
|
||||
`CREATE TABLE IF NOT EXISTS TrustedData (
|
|
||||
Id integer PRIMARY KEY autoincrement, |
|
||||
IdFieldsAnswers integer NOT NULL, |
|
||||
DtInsert TIMESTAMP NOT NULL, |
|
||||
Active integer NOT NULL, |
|
||||
FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id) |
|
||||
|
Images text NOT NULL, |
||||
|
Latitude real NOT NULL, |
||||
|
Longitude real NOT NULL, |
||||
|
Passable INTERGER NOT NULL |
||||
);`,
|
);`,
|
||||
]; |
]; |
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Users (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Email text NOT NULL,
|
||||
|
// FirstName text NOT NULL,
|
||||
|
// SurName text NOT NULL,
|
||||
|
// Avatar text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Profiles (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS UsersProfiles (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdUsers integer NOT NULL,
|
||||
|
// IdProfiles integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdUsers) REFERENCES Users (Id),
|
||||
|
// FOREIGN KEY (IdProfiles) REFERENCES Profiles (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Permissions (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS ProfilesPermissions (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdProfiles integer NOT NULL,
|
||||
|
// IdPermissions integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdProfiles) REFERENCES Profiles (Id),
|
||||
|
// FOREIGN KEY (IdPermissions) REFERENCES Permissions (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FormsOrigins (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Forms (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFormsOrigins integer NOT NULL,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Description text NOT NULL,
|
||||
|
// DtCreation TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFormsOrigins) REFERENCES FormsOrigins (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FieldsDataTypes (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Description text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Fields (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFieldsDataTypes integer NOT NULL,
|
||||
|
// Name text NOT NULL,
|
||||
|
// Description text NOT NULL,
|
||||
|
// FillingClue text NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFieldsDataTypes) REFERENCES FieldsDataTypes (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FormsFields (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdForms integer NOT NULL,
|
||||
|
// IdFields integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdForms) REFERENCES Forms (Id),
|
||||
|
// FOREIGN KEY (IdFields) REFERENCES Fields (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS Alternatives (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// Response text NOT NULL,
|
||||
|
// ShortResponse text NOT NULL,
|
||||
|
// Description text NOT NULL,
|
||||
|
// Active integer NOT NULL
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FieldsAlternatives (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFields integer NOT NULL,
|
||||
|
// IdAlternatives integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFields) REFERENCES Fields (Id),
|
||||
|
// FOREIGN KEY (IdAlternatives) REFERENCES Alternatives (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS FieldsAnswers (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFields integer NOT NULL,
|
||||
|
// Value text NOT NULL,
|
||||
|
// DtFilling TIMESTAMP NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFields) REFERENCES Fields (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS UsersInformerFieldsAnswers (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdUsersInformer integer NOT NULL,
|
||||
|
// IdFieldsAnswers integer NOT NULL,
|
||||
|
// Latitude real NULL,
|
||||
|
// Longitude real NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdUsersInformer) REFERENCES Users (Id),
|
||||
|
// FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS UsersEndorsementFieldsAnswers (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdUsersEndorsement integer NOT NULL,
|
||||
|
// IdFieldsAnswers integer NOT NULL,
|
||||
|
// Latitude real NULL,
|
||||
|
// Longitude real NULL,
|
||||
|
// IsTrustable integer NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdUsersEndorsement) REFERENCES Users (Id),
|
||||
|
// FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS PreliminaryData (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFieldsAnswers integer NOT NULL,
|
||||
|
// DtInsert TIMESTAMP NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id)
|
||||
|
// );`,
|
||||
|
|
||||
|
// `CREATE TABLE IF NOT EXISTS TrustedData (
|
||||
|
// Id integer PRIMARY KEY autoincrement,
|
||||
|
// IdFieldsAnswers integer NOT NULL,
|
||||
|
// DtInsert TIMESTAMP NOT NULL,
|
||||
|
// Active integer NOT NULL,
|
||||
|
// FOREIGN KEY (IdFieldsAnswers) REFERENCES FieldsAnswers (Id)
|
||||
|
// );`,
|
||||
|
// ];
|
||||
|
|
||||
export default init_queries; |
export default init_queries; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue