Skip to content

Commit

Permalink
Merge pull request #66 from snek-at/update-snekset-ba1
Browse files Browse the repository at this point in the history
Update snekset ba1 to implement 2 (Migrate: Latest Sub Version 01.09.2020)
  • Loading branch information
schettn authored Sep 1, 2020
2 parents 115b57e + 214ca59 commit f5aa706
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 31 deletions.
25 changes: 13 additions & 12 deletions src/templates/snek/gql/mutations/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ import gql from "graphql-tag";
*/
const registration = gql`
mutation registration($token: String!, $values: GenericScalar!) {
registration: registrationFormPage(
url: "/registration/",
token: $token,
values: $values) {
result
errors {
name
errors
}
registration: personRegistrationFormPage(
url: "/person-registration-form/"
token: $token
values: $values
) {
result
errors {
name
errors
}
}
}
`;

Expand All @@ -40,9 +41,9 @@ const registration = gql`
* @description A mutation to cache user information server side
*/
const cache = gql`
mutation cache($token: String!, $platformData: String!) {
cache: cacheUser(token: $token, platformData: $platformData) {
user {
mutation cache($token: String!, $personName: String!, $cache: String!) {
cache: cacheUser(token: $token, personName: $personName, cache: $cache) {
personPage {
id
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/templates/snek/gql/queries/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import gql from "graphql-tag";
*/
const gitlabServer = gql`
query gitLabServers($token: String!) {
page(slug: "registration", token: $token) {
... on RegistrationFormPage {
page(slug: "person-registration-form", token: $token) {
... on PersonRegistrationFormPage {
supportedGitlabs {
... on Gitlab_Server {
... on GitlabServer {
id
organisation
domain
Expand Down Expand Up @@ -53,7 +53,7 @@ const allPageUrls = gql`
*/
const allUserPageUrls = gql`
query userPages($token: String!) {
page(slug: "user", token: $token) {
page(slug: "people", token: $token) {
children {
slug
title
Expand Down
38 changes: 31 additions & 7 deletions src/templates/snek/gql/queries/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,48 @@ const whoami = gql`
/**
* Get user profile.
*
* @param {string} slug Slug: <user_<username>>
* @param {string} slug Slug: <p-<personName>>
* @param {string} token A users JWT
* @returns {string} A profile page of a user
* @description A query to fetch profile data
*/
const profile = gql`
query profile($slug: String!, $token: String!) {
profile: page(slug: $slug, token: $token) {
... on ProfilePage {
username
page(slug: $slug, token: $token) {
... on PersonFormPage {
personName: title
firstName
lastName
email
verified
platformData
platformData: cache
sources
bids
person {
cache
sources
}
tids
bids
follows {
personName: slug
}
followedBy {
personName: slug
}
likes {
personName: slug
}
likedBy {
personName: slug
}
achievements {
id
title
image {
src
imageSourceUrl
}
points
}
}
}
}
Expand Down
45 changes: 37 additions & 8 deletions src/templates/snek/gql/tasks/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,39 @@ interface CacheData {
*/
interface ProfileData {
profile: {
username: string;
profileName: string;
firstName: string;
lastName: string;
email: string;
verified: string;
platformData: string;
sources: string;
bids: string;
tids: string;
person: {
cache: string;
sources: string;
};
follows: {
personName: string;
}[];
followedBy: {
personName: string;
}[];
likes: {
personName: string;
}[];
likedBy: {
personName: string;
}[];
achievements: {
id: string;
title: string;
image: {
src: string;
imageSourceUrl: string;
};
points: string;
};
};
}

Expand Down Expand Up @@ -87,16 +111,21 @@ class SnekGqlUserTasks {
/**
* Cache a user.
*
* @param {string} platformData A serialized JSON object to be cached
* @param {string} personName The name of a users person page
* @param {string} cache A serialized JSON object to be cached
* @returns {Promise<ApolloResult<CacheData>>} Cache data
*/
async cache(platformData: string): Promise<ApolloResult<CacheData>> {
async cache(
personName: string,
cache: string
): Promise<ApolloResult<CacheData>> {
const response = await this.parent.run<CacheData>(
"mutation",
this.parent.template.mutations.user.cache,
{
token: await this.parent.session.upToDateToken(),
platformData,
personName,
cache,
}
);

Expand All @@ -106,15 +135,15 @@ class SnekGqlUserTasks {
/**
* Get profile.
*
* @param {string} slug Slug: <user_<username>>
* @param {string} personName personName: <schettn>
* @returns {Promise<ApolloResult<ProfileData>>} The profile page of a user
*/
async profile(slug: string): Promise<ApolloResult<ProfileData>> {
async profile(personName: string): Promise<ApolloResult<ProfileData>> {
const response = await this.parent.run<ProfileData>(
"query",
this.parent.template.queries.user.profile,
{
slug,
slug: `p-${personName}`,
token: await this.parent.session.upToDateToken(),
}
);
Expand Down

0 comments on commit f5aa706

Please sign in to comment.