diff --git a/controllers/tenantController.go b/controllers/tenantController.go index 2973d57..e329cc9 100644 --- a/controllers/tenantController.go +++ b/controllers/tenantController.go @@ -67,7 +67,17 @@ func (ctl *TenantController) GetAllTenants(c *fiber.Ctx) error { } func (ctl *TenantController) GetTenantLocations(c *fiber.Ctx) error { - tid, _ := strconv.Atoi(c.Query("tenantid")) + tidStr := c.Query("tenantid") + if tidStr == "" { + tidStr = c.Query("tenantId") + } + if tidStr == "" { + tidStr = c.Query("tenantID") + } + if tidStr == "" { + tidStr = c.Query("tenant_id") + } + tid, _ := strconv.Atoi(strings.TrimSpace(tidStr)) data, err := ctl.tenantService.GetTenantLocations(tid) if err != nil { @@ -429,10 +439,108 @@ func (ctl *TenantController) CreateTenantUser(c *fiber.Ctx) error { } func (ctl *TenantController) GetTenantInfo(c *fiber.Ctx) error { - tid, _ := strconv.Atoi(strings.TrimSpace(c.Query("tenantid"))) - locationid, _ := strconv.Atoi(strings.TrimSpace(c.Query("locationid"))) + log.Printf("[DEBUG] GetTenantInfo OriginalURL: %s, Headers: %v", c.OriginalURL(), c.GetReqHeaders()) + + // Parse tenant ID + tidStr := c.Query("tenantid") + if tidStr == "" { + tidStr = c.Query("tenantId") + } + if tidStr == "" { + tidStr = c.Query("tenantID") + } + if tidStr == "" { + tidStr = c.Query("tenant_id") + } + if tidStr == "" { + tidStr = c.Get("tenantid") + } + if tidStr == "" { + tidStr = c.Get("tenantId") + } + if tidStr == "" { + tidStr = c.Get("tenantID") + } + if tidStr == "" { + tidStr = c.Get("tenant_id") + } + tid, _ := strconv.Atoi(strings.TrimSpace(tidStr)) - data, err := ctl.tenantService.GetTenantByID(tid, locationid) + // Parse location ID + lidStr := c.Query("locationid") + if lidStr == "" { + lidStr = c.Query("locationId") + } + if lidStr == "" { + lidStr = c.Query("locationID") + } + if lidStr == "" { + lidStr = c.Query("location_id") + } + if lidStr == "" { + lidStr = c.Get("locationid") + } + if lidStr == "" { + lidStr = c.Get("locationId") + } + if lidStr == "" { + lidStr = c.Get("locationID") + } + if lidStr == "" { + lidStr = c.Get("location_id") + } + locationid, _ := strconv.Atoi(strings.TrimSpace(lidStr)) + + // Parse user ID + uidStr := c.Query("userid") + if uidStr == "" { + uidStr = c.Query("userId") + } + if uidStr == "" { + uidStr = c.Query("userID") + } + if uidStr == "" { + uidStr = c.Query("user_id") + } + if uidStr == "" { + uidStr = c.Query("appuserid") + } + if uidStr == "" { + uidStr = c.Query("appuserId") + } + if uidStr == "" { + uidStr = c.Query("appuserID") + } + if uidStr == "" { + uidStr = c.Query("appuser_id") + } + if uidStr == "" { + uidStr = c.Get("userid") + } + if uidStr == "" { + uidStr = c.Get("userId") + } + if uidStr == "" { + uidStr = c.Get("userID") + } + if uidStr == "" { + uidStr = c.Get("user_id") + } + if uidStr == "" { + uidStr = c.Get("appuserid") + } + if uidStr == "" { + uidStr = c.Get("appuserId") + } + if uidStr == "" { + uidStr = c.Get("appuserID") + } + if uidStr == "" { + uidStr = c.Get("appuser_id") + } + userid, _ := strconv.Atoi(strings.TrimSpace(uidStr)) + + data, err := ctl.tenantService.GetTenantByID(tid, locationid, userid) if err != nil { return c.Status(http.StatusInternalServerError).JSON(fiber.Map{ "code": http.StatusInternalServerError, diff --git a/nearle b/nearle new file mode 100755 index 0000000..f526bcc Binary files /dev/null and b/nearle differ diff --git a/repositories/tenantRepository.go b/repositories/tenantRepository.go index 2f4cc38..1e9405e 100644 --- a/repositories/tenantRepository.go +++ b/repositories/tenantRepository.go @@ -30,7 +30,7 @@ type TenantRepository interface { CheckTenantByNo(cno string) int CreateTenantUser(data models.Tenants) (bool, error) GetUserByNo(cno string) models.UserInfo - GetTenantByID(tid int, locationid int) (models.Tenantinfo, error) + GetTenantByID(tid int, locationid int, userid int) (models.Tenantinfo, error) GetTenantByKeyword(keyword string) ([]models.TenantSearch, error) } @@ -135,16 +135,15 @@ func (r *tenantRepository) GetAllTenants(pageno, pagesize, aid int, status, tena func (r *tenantRepository) GetTenantLocations(tid int) ([]models.Tenantlocations, error) { var data []models.Tenantlocations - q1 := `SELECT a.*, b.roleid FROM tenantlocations a - LEFT JOIN app_users b ON a.locationid = b.locationid - AND a.tenantid = b.tenantid - WHERE a.tenantid = ?` + q1 := `SELECT * FROM tenantlocations WHERE tenantid = ?` if err := r.db.Raw(q1, tid).Find(&data).Error; err != nil { return nil, err } - print(q1) + for i := range data { + data[i].Status = strings.ToLower(data[i].Status) + } return data, nil } @@ -651,9 +650,17 @@ func (r *tenantRepository) GetUserByNo(cno string) models.UserInfo { return user } -func (r *tenantRepository) GetTenantByID(tid int, locationid int) (models.Tenantinfo, error) { +func (r *tenantRepository) GetTenantByID(tid int, locationid int, userid int) (models.Tenantinfo, error) { var data models.Tenantinfo + if locationid == 0 && userid > 0 { + var userLocationID int + err := r.db.Table("app_users").Select("locationid").Where("userid = ?", userid).Row().Scan(&userLocationID) + if err == nil && userLocationID > 0 { + locationid = userLocationID + } + } + q1 := ` SELECT a.*,b.categoryname,c.locationname AS applocation, d.allocationid AS allocationmode,e.typename AS allocationtype,e.mapid AS allocationid,f.locationid, f.locationname, f.contactno as locationcontact @@ -678,6 +685,8 @@ func (r *tenantRepository) GetTenantByID(tid int, locationid int) (models.Tenant return data, err } + data.Status = strings.ToLower(data.Status) + return data, nil } diff --git a/repositories/userRepository.go b/repositories/userRepository.go index 8533ea0..a3fd4e0 100644 --- a/repositories/userRepository.go +++ b/repositories/userRepository.go @@ -83,6 +83,11 @@ func (r *userRepository) GetAllUsers(roleID, tenantID, pageno, pagesize int, key if err := r.db.Raw(queryBuilder.String(), params...).Scan(&users).Error; err != nil { return nil, err } + + for i := range users { + users[i].Status = strings.ToLower(users[i].Status) + } + return users, nil } @@ -93,7 +98,7 @@ func (r *userRepository) GetUserByID(uid int) (models.UserInfo, error) { a.firstname,a.lastname,concat(a.firstname,' ',a.lastname) as fullname,a.password,a.address,a.suburb,a.city,a.state,a.postcode, a.userfcmtoken,a.pin,a.deviceid,a.devicetype,a.tenantid,a.shiftid,a.locationid, a.applocationid,b.locationname as applocation,b.latitude as applatitude,b.longitude as applongitude, b.radius as appradius, - concat(c.starttime, ' - ', c.endtime) as shiftname + concat(c.starttime, ' - ', c.endtime) as shiftname, a.status FROM app_users a INNER JOIN app_location b ON a.applocationid = b.applocationid LEFT JOIN ridershifts c ON a.shiftid = c.shiftid @@ -103,6 +108,8 @@ func (r *userRepository) GetUserByID(uid int) (models.UserInfo, error) { return models.UserInfo{}, err } + user.Status = strings.ToLower(user.Status) + return user, nil } @@ -248,7 +255,7 @@ func (r *userRepository) GetUserById(uid int) (models.UserInfo, error) { q1 := `SELECT a.userid,a.authname,a.email,a.configid,a.roleid,a.authmode,a.contactno, a.firstname,a.lastname,concat(a.firstname,' ',a.lastname) as fullname,a.password,a.address,a.suburb,a.city,a.state,a.postcode, a.userfcmtoken,a.pin,a.deviceid,a.devicetype,a.tenantid,a.shiftid, - a.applocationid,b.locationname as applocation,b.latitude as applatitude,b.longitude as applongitude, b.radius as appradius , concat(c.starttime, ' - ', c.endtime) as shiftname + a.applocationid,b.locationname as applocation,b.latitude as applatitude,b.longitude as applongitude, b.radius as appradius , concat(c.starttime, ' - ', c.endtime) as shiftname, a.status FROM app_users a INNER JOIN app_location b on a.applocationid=b.applocationid LEFT JOIN ridershifts c ON a.shiftid = c.shiftid @@ -258,6 +265,8 @@ func (r *userRepository) GetUserById(uid int) (models.UserInfo, error) { return models.UserInfo{}, err } + user.Status = strings.ToLower(user.Status) + return user, nil } diff --git a/scratch/package-lock.json b/scratch/package-lock.json new file mode 100644 index 0000000..0a08e25 --- /dev/null +++ b/scratch/package-lock.json @@ -0,0 +1,490 @@ +{ + "name": "scratch", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "axios": "^1.18.1", + "pg": "^8.22.0" + } + }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "license": "MIT", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.18.1.tgz", + "integrity": "sha512-3nTvFlvpn9Zu/RkHUqtc7/+al4UpRW5az71ap5zccp6e8RAYEzhMTecX8Dz1wWDYrPpUoB1HAQEGEAEvUr7S9g==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.16.0", + "form-data": "^4.0.5", + "https-proxy-agent": "^5.0.1", + "proxy-from-env": "^2.1.0" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/follow-redirects": { + "version": "1.16.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", + "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz", + "integrity": "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.4", + "mime-types": "^2.1.35" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "license": "MIT", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/pg": { + "version": "8.22.0", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.22.0.tgz", + "integrity": "sha512-8wih1vVIBMxoUM2oB4soJsD9tDnDpLv4OXBJ+EJzFsvycD+lfyIreC2gGHq78f8jbLLt+bvlPTFdFZfJkOuzAA==", + "license": "MIT", + "dependencies": { + "pg-connection-string": "^2.14.0", + "pg-pool": "^3.14.0", + "pg-protocol": "^1.15.0", + "pg-types": "2.2.0", + "pgpass": "1.0.5" + }, + "engines": { + "node": ">= 16.0.0" + }, + "optionalDependencies": { + "pg-cloudflare": "^1.4.0" + }, + "peerDependencies": { + "pg-native": ">=3.0.1" + }, + "peerDependenciesMeta": { + "pg-native": { + "optional": true + } + } + }, + "node_modules/pg-cloudflare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.4.0.tgz", + "integrity": "sha512-Vo7z/6rrQYxpNRylp4Tlob2elzbh+N/MOQbxFVWCxS7oEx6jF53GTJFxK2WWpKuBRkmiin4Mt+xofFDjx09R0A==", + "license": "MIT", + "optional": true + }, + "node_modules/pg-connection-string": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.14.0.tgz", + "integrity": "sha512-XwWDGcLRGCXAR8F/AM5bG7Q+A3Wm2s6QeEjlOKZLlH3UYcguiqCWKyWXVag5TLTIjR7oOJUY8kcADaZgWPyLeg==", + "license": "MIT" + }, + "node_modules/pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", + "license": "ISC", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/pg-pool": { + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.14.0.tgz", + "integrity": "sha512-gKtPkFdQPU3DksooVLi9LsjZxrsBUZIpa+7aVx+LV5pNh0KzP4Zleud2po+ConrxbuXGBJ6Hfer6hdgpIBpBaw==", + "license": "MIT", + "peerDependencies": { + "pg": ">=8.0" + } + }, + "node_modules/pg-protocol": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.15.0.tgz", + "integrity": "sha512-cq9sECI5s0+uPUXjbz8ioyPJni6RzsRib0US67i5IoTZKw8fNeYlVE7u8F4dG7vEJJtc5wdD1K189lCCUwqWTQ==", + "license": "MIT" + }, + "node_modules/pg-types": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", + "license": "MIT", + "dependencies": { + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.4", + "postgres-interval": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/pgpass": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", + "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", + "license": "MIT", + "dependencies": { + "split2": "^4.1.0" + } + }, + "node_modules/postgres-array": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/postgres-bytea": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.1.tgz", + "integrity": "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-date": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", + "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-interval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", + "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", + "license": "MIT", + "dependencies": { + "xtend": "^4.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/proxy-from-env": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", + "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "license": "MIT", + "engines": { + "node": ">=0.4" + } + } + } +} diff --git a/scratch/package.json b/scratch/package.json new file mode 100644 index 0000000..cff4a9a --- /dev/null +++ b/scratch/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "axios": "^1.18.1", + "pg": "^8.22.0" + } +} diff --git a/scratch/query_stores.js b/scratch/query_stores.js index b1592fe..9598426 100644 --- a/scratch/query_stores.js +++ b/scratch/query_stores.js @@ -14,15 +14,17 @@ async function main() { await client.connect(); console.log('Connected to PostgreSQL successfully!'); - // Get Suriya Store locations - const locationsRes = await client.query('SELECT locationid, tenantid, locationname, email, contactno, status FROM tenantlocations WHERE tenantid = 1135'); - console.log('\n--- SURIYA STORE LOCATIONS (tenantid = 1135) ---'); - console.table(locationsRes.rows); - - // Get all users associated with tenantid = 1135 - const usersRes = await client.query('SELECT userid, authname, firstname, email, contactno, roleid, locationid, status FROM app_users WHERE tenantid = 1135'); - console.log('\n--- USERS ASSOCIATED WITH tenantid = 1135 ---'); - console.table(usersRes.rows); + const query = ` + SELECT a.tenantcustomerid, a.customerid, a.tenantid, a.locationid, + b.tenantname, c.locationname + FROM tenantcustomers a + LEFT JOIN tenants b ON a.tenantid = b.tenantid + INNER JOIN tenantlocations c ON a.locationid = c.locationid + WHERE a.tenantid = 1135 + `; + const res = await client.query(query); + console.log('\n--- Tenant Customers Links (tid = 1135) ---'); + console.table(res.rows); } catch (err) { console.error('Error connecting:', err); diff --git a/services/tenantService.go b/services/tenantService.go index b1c9609..a92ef10 100644 --- a/services/tenantService.go +++ b/services/tenantService.go @@ -24,7 +24,7 @@ type TenantService interface { CreateTenantLocation(data models.Tenantlocations) map[string]interface{} UpdateTenantLocation(data models.Tenantlocations) map[string]interface{} CreateTenantUser(data models.Tenants) (models.UserInfo, error) - GetTenantByID(tid int, locationid int) (models.Tenantinfo, error) + GetTenantByID(tid int, locationid int, userid int) (models.Tenantinfo, error) GetTenantByKeyword(keyword string) ([]models.TenantSearch, error) } @@ -158,8 +158,8 @@ func (s *tenantService) CreateTenantUser(data models.Tenants) (models.UserInfo, return result, nil } -func (s *tenantService) GetTenantByID(tid int, locationid int) (models.Tenantinfo, error) { - return s.repo.GetTenantByID(tid, locationid) +func (s *tenantService) GetTenantByID(tid int, locationid int, userid int) (models.Tenantinfo, error) { + return s.repo.GetTenantByID(tid, locationid, userid) } func (s *tenantService) GetTenantByKeyword(keyword string) ([]models.TenantSearch, error) { diff --git a/services/userService.go b/services/userService.go index b5bbd66..f458120 100644 --- a/services/userService.go +++ b/services/userService.go @@ -88,7 +88,7 @@ func (s *userService) AppLogin(user models.User) (models.TenantUserInfo, fiber.M } // Inactive account - if status == "InActive" { + if strings.EqualFold(status, "InActive") { resp := fiber.Map{ "status": false, "code": 403, @@ -147,7 +147,7 @@ func (s *userService) AppLogin(user models.User) (models.TenantUserInfo, fiber.M // ✅ Check if assigned store is inactive if info.Locationid > 0 { storeStatus := s.repo.GetLocationStatus(info.Locationid) - if storeStatus == "InActive" { + if strings.EqualFold(storeStatus, "InActive") { resp := fiber.Map{ "status": false, "code": 403, @@ -213,7 +213,7 @@ func (s *userService) TenantWebLogin(user models.User) (models.TenantUserInfo, m } } - if status == "InActive" { + if strings.EqualFold(status, "InActive") { return models.TenantUserInfo{}, map[string]interface{}{ "status": false, "code": 403, @@ -272,7 +272,7 @@ func (s *userService) TenantWebLogin(user models.User) (models.TenantUserInfo, m // Step 6: Check if assigned store is inactive if info.Locationid > 0 { storeStatus := s.repo.GetLocationStatus(info.Locationid) - if storeStatus == "InActive" { + if strings.EqualFold(storeStatus, "InActive") { return models.TenantUserInfo{}, map[string]interface{}{ "status": false, "code": 403,