Skip to content

Commit

Permalink
Merge pull request #393 from cofacts/awardee-check
Browse files Browse the repository at this point in the history
Add awardee check to mgpAwardee
  • Loading branch information
MrOrz committed Apr 18, 2024
2 parents 2042fa4 + ef7e856 commit 6fd0218
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/graphql/resolvers/Query.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UserArticleLink from 'src/database/models/userArticleLink';
import UserSettings from 'src/database/models/userSettings';
import AppVariable from 'src/database/models/appVariable';
import { groupEventQueue, expiredGroupEventQueue } from 'src/lib/queues';
import { processConnection } from '../utils/connection';

Expand All @@ -26,4 +27,10 @@ export default {
orderBy,
});
},

async isMgpAwardee(root, args, { userId }) {
const awardees = (await AppVariable.get('mgpAwardees')) || [];

return awardees.includes(userId);
},
};
2 changes: 2 additions & 0 deletions src/graphql/typeDefs.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Query {

# Get user's notification setting
setting: UserSetting @auth(check: ["userId"])

isMgpAwardee: Boolean @auth(check: ["userId"])
}

type Mutation {
Expand Down
30 changes: 28 additions & 2 deletions src/liff/pages/MgpAwardee.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<script>
import { onMount } from 'svelte';
import { gql } from '../lib';
const userId = liff.getDecodedIDToken().sub;
let iframeUrl = `https://www.surveycake.com/s/Xx6mp?ssn0=${userId}`
let iframeUrl = `https://www.surveycake.com/s/Xx6mp?ssn0=${userId}`;
let state = 'LOADING'; // LOADING, INVALID, VALID
onMount(async () => {
const { data: { isMgpAwardee } } = await gql`
{
isMgpAwardee
}
`();
state = isMgpAwardee ? 'VALID' : 'INVALID';
});
</script>

<style>
Expand All @@ -9,10 +23,22 @@
height: 100vh;
border: 0;
}
p {
text-align: center;
margin-top: 50vh;
transform: translateY(-50%);
}
</style>

<svelte:head>
<title>得獎者@Cofacts x 第四屆 MyGoPen 謠言惑眾獎</title>
</svelte:head>

<iframe title="謠言惑眾獎得獎者" src={iframeUrl} />
{#if state === 'LOADING'}
<p>正在檢查您是否為得獎者⋯⋯</p>
{:else if state === 'INVALID'}
<p>您並非得獎者,無法查看此頁面。</p>
{:else}
<iframe title="謠言惑眾獎得獎者" src={iframeUrl} />
{/if}

0 comments on commit 6fd0218

Please sign in to comment.