Skip to content

Commit

Permalink
feat: add awardee check to mgpAwardee
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Apr 18, 2024
1 parent 2042fa4 commit c29d97b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
8 changes: 8 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';

Check failure on line 3 in src/graphql/resolvers/Query.js

View workflow job for this annotation

GitHub Actions / install-and-test

Unable to resolve path to module 'src/database/models/AppVariable'

Check failure on line 3 in src/graphql/resolvers/Query.js

View workflow job for this annotation

GitHub Actions / install-and-test

Unable to resolve path to module 'src/database/models/AppVariable'
import { groupEventQueue, expiredGroupEventQueue } from 'src/lib/queues';
import { processConnection } from '../utils/connection';

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

async isMgpAwardee(root, args, { userId }) {
const awardees = ((await AppVariable.get('mgpAwardees')) || '')
.trim()
.split('\n');
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';
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 () => {
isLoadingData = true;

Check failure on line 9 in src/liff/pages/MgpAwardee.svelte

View workflow job for this annotation

GitHub Actions / install-and-test

'isLoadingData' is not defined

Check failure on line 9 in src/liff/pages/MgpAwardee.svelte

View workflow job for this annotation

GitHub Actions / install-and-test

'isLoadingData' is not defined
const { data: {isMgpAwardee} } = await gql`

Check failure on line 10 in src/liff/pages/MgpAwardee.svelte

View workflow job for this annotation

GitHub Actions / install-and-test

'gql' is not defined

Check failure on line 10 in src/liff/pages/MgpAwardee.svelte

View workflow job for this annotation

GitHub Actions / install-and-test

'gql' is not defined
{
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 c29d97b

Please sign in to comment.