diff --git a/api/index.js b/api/index.js index 26c11be..9c73279 100644 --- a/api/index.js +++ b/api/index.js @@ -1,26 +1,21 @@ const app = require('express')() const bodyParser = require('body-parser') - const swarmRoutes = require("./swarm.js") -module.exports = { path: '/api', handler: app } - +// Express Settings app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.json()) - - var timeout = require('connect-timeout'); app.use(timeout(1000*60*30)); +// Swarm Route app.use("/swarm", swarmRoutes) +// General Index Message app.get('/' ,(req, res) => { res.write('Hey!'); res.end() }) +module.exports = { path: '/api', handler: app } -app.get('/authenticate' ,(req, res) => { - res.write('Hey!'); - res.end() -}) \ No newline at end of file diff --git a/components/Comps/Loading.vue b/components/Comps/Loading.vue new file mode 100644 index 0000000..81486b3 --- /dev/null +++ b/components/Comps/Loading.vue @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/components/Header.vue b/components/Header.vue index 8f13a8e..6acd858 100644 --- a/components/Header.vue +++ b/components/Header.vue @@ -6,8 +6,8 @@ Logo This is header section -
- +
+
diff --git a/components/Home.vue b/components/Home.vue index 197a864..c9f5dff 100644 --- a/components/Home.vue +++ b/components/Home.vue @@ -13,26 +13,63 @@
-
-
+
+
- - Loading... - + +
-
+
- - Loading... - + +
+ +
+
+
+ +
+
+
+
+
+
+ + + + + +
+
+ +
+
+ +
+
+
+ +
+
+
@@ -46,9 +83,17 @@ export default { data(){ return { user: null, - enabled_bot: false, + configs: { + enabled: false, + loading: true, + checkins: { + enabled: false, + loading: true, + venues: {}, + } + }, + venue_search: '', bot_enabled_spinner: '', - enabled_auto_checki_in: false, auto_check_in_enabled_spinner: '', } }, @@ -56,11 +101,22 @@ export default { if(this.$auth.user?.user?.firstName){ this.user = this.$auth.user.user; } + + console.log('before mutlaq expierment') + this.$MFO_UTILS.setCheckInVenueInformation({id: 123}) console.log("mounted"); this.saveUser(); }, watch: { - enabled_bot: async function(val, oldVal) { + venue_search: async function(val){ + if(val.length != 0){ + //console.log(val); + let venue_name = await this.$MFO_UTILS.searchVenues(val); + console.log(venue_name[0]?.name); + } + + }, + 'configs.enabled': async function(val, oldVal) { this.bot_enabled_spinner = ''; console.log(val); try { @@ -71,7 +127,7 @@ export default { this.bot_enabled_spinner = 'd-none'; }, - enabled_auto_checki_in: async function(val, oldVal) { + 'configs.checkins.enabled': async function(val, oldVal) { this.auto_check_in_enabled_spinner = ''; console.log(val); try { @@ -83,7 +139,6 @@ export default { this.auto_check_in_enabled_spinner = 'd-none'; } }, - methods: { async saveUser() { //console.log(this.$auth.strategy.token.get()); @@ -96,15 +151,15 @@ export default { const userConfigs = await this.$MFO_UTILS.getConfigsFromFirebase(); if(userConfigs){ if(userConfigs?.enabled == true){ - this.enabled_bot = true; + this.configs.enabled = true; } - if(userConfigs?.settings?.auto_check_in?.enabled == true){ - this.enabled_auto_checki_in = true; + if(userConfigs?.settings?.checkins?.enabled == true){ + this.configs.checkins.enabled = true; } - this.auto_check_in_enabled_spinner = 'd-none'; - this.bot_enabled_spinner = 'd-none'; + this.configs.loading = false; + this.configs.checkins.loading = false; } console.log(userConfigs) diff --git a/layouts/default.vue b/layouts/default.vue index bfda147..ca2e4a4 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -1,7 +1,7 @@ diff --git a/pages/login.vue b/pages/login.vue index 40333bd..608ab0b 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -19,7 +19,7 @@ export default { async loginSwarm() { console.log('before call'); await this.$auth.loginWith('social').catch(e => { - console.log('hello') + console.log('hello error login') }) }, }, diff --git a/utils/utils.js b/utils/utils.js index 70b7883..dc21e21 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,4 +1,6 @@ // * with help of Alexander Lichter, Apr 18, 2020, https://blog.lichter.io/posts/nuxt-api-call-organization-and-decoupling/ +const axios = require('axios').default; + export default ($firebase, $auth) => () => ({ async createUserInFirebase() { @@ -60,7 +62,7 @@ export default ($firebase, $auth) => () => ({ try { const configsRef = $firebase.firestore.collection("configs").doc($auth.user.user.id); await configsRef.update({settings: { - auto_check_in: { + checkins: { enabled: value } } }); @@ -69,6 +71,57 @@ export default ($firebase, $auth) => () => ({ console.log(error); return false; } + }, + + async searchVenues(name){ + try { + let venues_result = await axios.get('https://api.foursquare.com/v3/places/search', { + params: { + near: 'Saudi Arabia', + query: name + }, + headers:{ + Authorization: 'fsq3mvJJUXXc2bwnfvTp3/YZfKabrAfiORz2rTyxJHTwEPQ=' + } + }); + + if(venues_result.data.results.length > 0){ + return venues_result.data.results; + } + + return {}; + } catch (error) { + console.log(error); + return false; + } + + + + }, + + async setCheckInVenueInformation(venue_info){ + try { + let venue_id = venue_info.id + + let venue_settings = { + settings: { + checkins: { + venues: {} + } + } + }; + + venue_settings.settings.checkins.venues[venue_id] = { + id: 123 + } + + const configsRef = $firebase.firestore.collection("configs").doc($auth.user.user.id); + await configsRef.update(venue_settings); + return true; + } catch (error) { + console.log(error); + return false; + } }