forked from cloudinary-devs/cloudybadge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maya Shavin
committed
Jan 31, 2020
1 parent
7a6abf3
commit 078f7c1
Showing
33 changed files
with
1,082 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.tabSize": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Database API (FAUNADB) | ||
|
||
We are using FaunaDB to create and maintain our DB for cloudyBadge. Below is some information about the structure of our DB | ||
|
||
## Main DB - cloudybadge | ||
|
||
`cloudybadge` is the child database of `cloudy`. Inside `cloudybadge` we will have `badges` which is our main collection of all the badges information. | ||
|
||
## Indexes | ||
|
||
Some of our indexes are as below: | ||
|
||
1. all_badges | ||
2. all_badges_per_event | ||
3. badge_by_editKey | ||
4. badge_by_viewKey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require('dotenv').config(); | ||
const { q, client } = require('./setup'); | ||
|
||
module.exports = async (req, res) => { | ||
try { | ||
const queryResponse = await client.query( | ||
q.Paginate( | ||
q.Match( | ||
q.Index(process.env.FAUNA_QUERY_EVENTS) | ||
) | ||
) | ||
); | ||
|
||
const data = queryResponse.data; | ||
const allEventsQuery = data.map(ref => q.Get(ref)); | ||
|
||
const response = await client.query(allEventsQuery) | ||
const events = response.map(entry => entry.data); | ||
|
||
return res.json({ | ||
events | ||
}); | ||
} catch(error) { | ||
return res.json({ | ||
error: error.message | ||
}); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require('dotenv').config(); | ||
const { q, client } = require('./setup'); | ||
|
||
module.exports = async (req, res) => { | ||
const eventId = req.query.id; | ||
// const getEvent = require('./getEvent'); | ||
|
||
try { | ||
const [eventResponse, queryResponse] = await Promise.all([client.query( | ||
q.Get( | ||
q.Match( | ||
q.Index(process.env.FAUNA_QUERY_EVENT), eventId | ||
) | ||
) | ||
), client.query( | ||
q.Paginate( | ||
q.Match( | ||
q.Index(process.env.FAUNA_QUERY_ALL_PER_EVENT), eventId | ||
) | ||
) | ||
)]); | ||
|
||
const badges = queryResponse.data; | ||
const allBadgesQuery = badges.map(ref => q.Get(ref)); | ||
|
||
const response = await client.query(allBadgesQuery); | ||
|
||
const users = response.map(badge => { | ||
delete badge.data.editKey; //remove Edit key | ||
return badge.data; | ||
}); | ||
|
||
return res.json({ | ||
users, | ||
event: eventResponse.data | ||
}); | ||
|
||
} catch(error) { | ||
console.error(error); | ||
|
||
return res.json({ | ||
error: error.message | ||
}); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require('dotenv').config(); | ||
const { q, client } = require('./setup'); | ||
|
||
module.exports = async (req, res) => { | ||
const eventId = req.query.id; | ||
try { | ||
const queryResponse = await client.query( | ||
q.Get( | ||
q.Match( | ||
q.Index(process.env.FAUNA_QUERY_EVENT), eventId | ||
) | ||
) | ||
); | ||
|
||
return res.json(queryResponse.data); | ||
} catch(error) { | ||
return res.json({ | ||
error: error.message | ||
}); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require('dotenv').config(); | ||
const { q, client } = require('./setup'); | ||
|
||
const getUserByKey = async (id, byKey) => { | ||
const indexQuery = `${process.env.FAUNA_QUERY_ONE_PREFIX}${byKey}`; | ||
|
||
try { | ||
return await client.query( | ||
q.Get( | ||
q.Match( | ||
q.Index(indexQuery), id | ||
) | ||
) | ||
); | ||
} catch (error) { | ||
return { | ||
error: error.message, | ||
} | ||
} | ||
} | ||
|
||
|
||
module.exports = async (req, res) => { | ||
const id = req.query.id; | ||
const voteId = req.query.vid; | ||
let isVoteIdValidate = false; | ||
let responseData = {}; | ||
|
||
if (voteId) { | ||
const voterQuery = await getUserByKey(voteId, 'voteid'); | ||
isVoteIdValidate = !!voterQuery; | ||
} | ||
|
||
responseData = await getUserByKey(id, 'viewkey'); | ||
|
||
if (responseData.error) { | ||
isVoteIdValidate = false; | ||
const editQuery = await getUserByKey(id, 'editkey'); | ||
|
||
responseData = editQuery; | ||
} | ||
|
||
if (responseData.data && responseData.data.editKey) { | ||
delete responseData.data.editKey; | ||
} | ||
|
||
return res.json({ | ||
info: responseData, | ||
hasVoter: isVoteIdValidate, | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require('dotenv').config(); | ||
const faunadb = require('faunadb'); | ||
|
||
const q = faunadb.query; | ||
const client = new faunadb.Client({ | ||
secret: process.env.FAUNADB | ||
}); | ||
|
||
module.exports = { | ||
client, | ||
q | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<template> | ||
<nuxt-link :to="link"> | ||
<button class="outline-none rounded-full hover:bg-grey-darker border-0 p-2"> | ||
<svg width="20" height="20" aria-hidden="true" focusable="false" data-icon="chevron-left" role="img" viewBox="0 0 320 512"> | ||
<path fill="#fff" d="M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z"/> | ||
</svg> | ||
</button> | ||
</nuxt-link> | ||
</template> | ||
<script> | ||
export default { | ||
props: { | ||
link: { | ||
type: String, | ||
require: true, | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<template> | ||
<div class="upload--result--wrapper flex mr-3"> | ||
<cld-image :public-id="badgeUrl" | ||
class="border-2 self-center" | ||
:transformation="transformation" | ||
height="800" crop="fill" | ||
/> | ||
</div> | ||
</template> | ||
<script> | ||
export default { | ||
props: { | ||
badgeUrl: { | ||
type: String, | ||
require: true, | ||
}, | ||
name: { | ||
type: String, | ||
default: '' | ||
}, | ||
company: { | ||
type: String, | ||
default: '' | ||
}, | ||
title: { | ||
type: String, | ||
default: '' | ||
}, | ||
avatarOverlay: { | ||
type: String, | ||
default: '' | ||
}, | ||
effect: { | ||
type: Object, | ||
default: () => ({}) | ||
} | ||
}, | ||
computed: { | ||
transformation() { | ||
return [{ | ||
overlay: this.avatarOverlay, | ||
radius:"max", | ||
width:"800", | ||
height:"800", | ||
x:"6", | ||
y:"320", | ||
crop:"thumb", | ||
...this.effect, | ||
}, { | ||
overlay: `text:Roboto_80:${this.name}`, | ||
y: "-1000" | ||
}, { | ||
overlay: `text:Roboto_50:${this.company}`, | ||
y: "-900" | ||
}] | ||
}, | ||
} | ||
} | ||
</script> |
Oops, something went wrong.