From e968124041db1806787f244f2bc08d1f9c55c6a5 Mon Sep 17 00:00:00 2001 From: ZhuoweiWen Date: Tue, 16 Jul 2024 11:03:56 -0400 Subject: [PATCH] Define database schema for organization Signed-off-by: ZhuoweiWen --- back-end/database/models.py | 16 ++++++++++++---- front-end/components/Upload.js | 16 ++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/back-end/database/models.py b/back-end/database/models.py index 37ea20f..c89af01 100755 --- a/back-end/database/models.py +++ b/back-end/database/models.py @@ -4,16 +4,24 @@ from sqlalchemy.orm import relationship from datetime import datetime +class organization(Base): + id = Column(Integer, primary_key=True) + name = Column(String(100), unique=True, nullable=False) + provider_id = Column(Integer) + brand_name = Column(String(50)) + users = relationship('User', back_populates='organization') + folders = relationship('folder', back_populates='user', cascade='all, delete') + towers = relationship('tower', back_populates='user', cascade='all, delete') + class user(Base): __tablename__ = 'user' id = Column(Integer, primary_key=True) username = Column(String(50), unique=True) password = Column(String(256)) - provider_id = Column(Integer) - brand_name = Column(String(50)) - folders = relationship('folder', back_populates='user', cascade='all, delete') - towers = relationship('tower', back_populates='user', cascade='all, delete') + organization_id = Column(Integer, ForeignKey('organization.id')) + organization = relationship('Organization', back_populates='users') + class tower(Base): __tablename__ = 'tower' diff --git a/front-end/components/Upload.js b/front-end/components/Upload.js index 45f9a5b..a0dd328 100755 --- a/front-end/components/Upload.js +++ b/front-end/components/Upload.js @@ -125,6 +125,7 @@ export default function Upload() { const currentYear = new Date().getFullYear(); const years = Array.from({ length: 10 }, (_, i) => currentYear - 5 + i); + const allowedExtensions = ["kml", "geojson", "csv"]; const fetchFolders = async () => { @@ -159,11 +160,22 @@ export default function Upload() { const handleFilingClick = (event) => { event.preventDefault(); + if (folderID === -1 && !files.some(file => file.file.name.endsWith('.csv'))) { + toast.error( + "Please upload your fabric", + { + position: toast.POSITION.TOP_RIGHT, + autoClose: 5000, + } + ); + return; // Stop the function if the condition is met + } + + const formData = new FormData(); formData.append("deadline", `${newDeadline.year}-${newDeadline.month}-03`); formData.append("importFolder", importFolderID); files.forEach((fileDetails) => { - const allowedExtensions = ["kml", "geojson", "csv"]; const fileExtension = fileDetails.file.name .split(".") .pop() @@ -208,7 +220,7 @@ export default function Upload() { } else if (response.status === 500 || response.status === 400) { setIsLoading(false); toast.error( - "Invalid File Format, please upload file with supported format", + "Error from our end, if issues persist, please contact support", { position: toast.POSITION.TOP_RIGHT, autoClose: 10000,