feat: save roles to backend

This commit is contained in:
vidvidvid
2022-01-16 15:15:00 +01:00
parent 94d7cf4e11
commit 9eb95828f6
7 changed files with 223 additions and 76 deletions

View File

@@ -74,6 +74,7 @@ input CreateQuestInput {
repetition : QuestRepetition_ActionEnum
cooldown : Int
skills_id : [uuid]!
roles_id : [uuid]!
}
input CreateQuestCompletionInput {

View File

@@ -0,0 +1 @@
alter table "public"."quest_role" add constraint "quest_role_quest_id_key" unique ("quest_id");

View File

@@ -0,0 +1 @@
alter table "public"."quest_role" drop constraint "quest_role_quest_id_key";

View File

@@ -5,7 +5,7 @@ import {
QuestRepetition_Enum,
} from '../../../../lib/autogen/hasura-sdk';
import { client } from '../../../../lib/hasuraClient';
import { isAllowedToCreateQuest } from './permissions';
// import { isAllowedToCreateQuest } from './permissions';
export async function createQuest(
playerId: string,
@@ -30,17 +30,20 @@ export async function createQuest(
throw new Error('Ethereum address not found for player');
}
const allowed = await isAllowedToCreateQuest(ethAddress);
if (!allowed) {
throw new Error('Player not allowed to create quests');
}
// const allowed = await isAllowedToCreateQuest(ethAddress);
// if (!allowed) {
// throw new Error('Player not allowed to create quests');
// }
const { skills_id: skillsId, ...questValues } = quest;
const { skills_id: skillsId, roles_id: rolesId, ...questValues } = quest;
const questInput: Quest_Insert_Input = {
...questValues,
repetition: questRepetition,
created_by_player_id: playerId,
quest_roles: {
data: rolesId.map((r, i) => ({ role: r, rank: i + 1 })),
},
quest_skills: {
data: skillsId.map((s) => ({ skill_id: s })),
},

View File

@@ -23,6 +23,7 @@ import React, { useEffect, useMemo, useState } from 'react';
import { Controller, FieldError, useForm } from 'react-hook-form';
import { QuestRepetitionHint, UriRegexp } from '../../utils/questHelpers';
import { RoleOption } from '../../utils/roleHelpers';
import { CategoryOption, SkillOption } from '../../utils/skillHelpers';
import { stateFromHTML } from '../../utils/stateFromHTML';
import { FlexContainer } from '../Container';
@@ -65,6 +66,7 @@ export interface CreateQuestFormInputs {
external_link: string | undefined | null;
cooldown: number | undefined | null;
skills: SkillOption[];
roles: RoleOption[];
}
const MetaFamGuildId = 'f94b7cd4-cf29-4251-baa5-eaacab98a719';
@@ -103,6 +105,7 @@ const getDefaultFormValues = (
...s,
}))
: [],
roles: [],
});
type FieldProps = {

View File

@@ -21,12 +21,13 @@ import { parseSkills } from 'utils/skillHelpers';
type Props = InferGetStaticPropsType<typeof getStaticProps>;
const extractFormData = (data: CreateQuestFormInputs) => {
const { skills, repetition, cooldown, ...createQuestInputs } = data;
const { skills, repetition, cooldown, roles, ...createQuestInputs } = data;
const convertedDescription = draftToHtml(
convertToRaw(createQuestInputs.description.getCurrentContent()),
);
return {
skills,
roles,
repetition,
cooldown,
title: createQuestInputs.title,
@@ -50,6 +51,7 @@ const CreateQuestPage: React.FC<Props> = ({
const onSubmit = (data: CreateQuestFormInputs) => {
const {
skills,
roles,
repetition,
cooldown,
...createQuestInputs
@@ -60,11 +62,17 @@ const CreateQuestPage: React.FC<Props> = ({
repetition: (data.repetition as unknown) as QuestRepetition_ActionEnum,
cooldown: transformCooldownForBackend(cooldown, repetition),
skills_id: skills.map((s) => s.id),
roles_id: roles.map((r) => r.value),
};
console.log(input);
// return;
createQuest({
input,
}).then((response) => {
console.log('response', response);
const createQuestResponse = response.data?.createQuest;
if (createQuestResponse?.success) {
router.push(`/quest/${createQuestResponse.quest_id}`);

View File

@@ -666,6 +666,7 @@ input CreateQuestInput {
external_link: String
guild_id: uuid!
repetition: QuestRepetition_ActionEnum
roles_id: [uuid]!
skills_id: [uuid]!
title: String!
}
@@ -3057,7 +3058,9 @@ type mutation_root {
delete data from the table: "quest_role"
"""
delete_quest_role(
"""filter the rows which have to be deleted"""
"""
filter the rows which have to be deleted
"""
where: quest_role_bool_exp!
): quest_role_mutation_response
@@ -3780,10 +3783,14 @@ type mutation_root {
insert data into the table: "quest_role"
"""
insert_quest_role(
"""the rows to be inserted"""
"""
the rows to be inserted
"""
objects: [quest_role_insert_input!]!
"""on conflict condition"""
"""
on conflict condition
"""
on_conflict: quest_role_on_conflict
): quest_role_mutation_response
@@ -3791,10 +3798,14 @@ type mutation_root {
insert a single row into the table: "quest_role"
"""
insert_quest_role_one(
"""the row to be inserted"""
"""
the row to be inserted
"""
object: quest_role_insert_input!
"""on conflict condition"""
"""
on conflict condition
"""
on_conflict: quest_role_on_conflict
): quest_role
@@ -4572,13 +4583,19 @@ type mutation_root {
update data of the table: "quest_role"
"""
update_quest_role(
"""increments the integer columns with given value of the filtered values"""
"""
increments the integer columns with given value of the filtered values
"""
_inc: quest_role_inc_input
"""sets the columns of the filtered rows to the given values"""
"""
sets the columns of the filtered rows to the given values
"""
_set: quest_role_set_input
"""filter the rows which have to be updated"""
"""
filter the rows which have to be updated
"""
where: quest_role_bool_exp!
): quest_role_mutation_response
@@ -4586,10 +4603,14 @@ type mutation_root {
update single row of the table: "quest_role"
"""
update_quest_role_by_pk(
"""increments the integer columns with given value of the filtered values"""
"""
increments the integer columns with given value of the filtered values
"""
_inc: quest_role_inc_input
"""sets the columns of the filtered rows to the given values"""
"""
sets the columns of the filtered rows to the given values
"""
_set: quest_role_set_input
pk_columns: quest_role_pk_columns_input!
): quest_role
@@ -9371,19 +9392,29 @@ type query_root {
fetch data from the table: "quest_role"
"""
quest_role(
"""distinct select on columns"""
"""
distinct select on columns
"""
distinct_on: [quest_role_select_column!]
"""limit the number of rows returned"""
"""
limit the number of rows returned
"""
limit: Int
"""skip the first n rows. Use only with order_by"""
"""
skip the first n rows. Use only with order_by
"""
offset: Int
"""sort the rows by one or more columns"""
"""
sort the rows by one or more columns
"""
order_by: [quest_role_order_by!]
"""filter the rows returned"""
"""
filter the rows returned
"""
where: quest_role_bool_exp
): [quest_role!]!
@@ -9391,23 +9422,35 @@ type query_root {
fetch aggregated fields from the table: "quest_role"
"""
quest_role_aggregate(
"""distinct select on columns"""
"""
distinct select on columns
"""
distinct_on: [quest_role_select_column!]
"""limit the number of rows returned"""
"""
limit the number of rows returned
"""
limit: Int
"""skip the first n rows. Use only with order_by"""
"""
skip the first n rows. Use only with order_by
"""
offset: Int
"""sort the rows by one or more columns"""
"""
sort the rows by one or more columns
"""
order_by: [quest_role_order_by!]
"""filter the rows returned"""
"""
filter the rows returned
"""
where: quest_role_bool_exp
): quest_role_aggregate!
"""fetch data from the table: "quest_role" using primary key columns"""
"""
fetch data from the table: "quest_role" using primary key columns
"""
quest_role_by_pk(quest_id: uuid!, role: String!): quest_role
"""
@@ -9632,43 +9675,69 @@ type quest {
where: quest_completion_bool_exp
): quest_completion_aggregate!
"""An array relationship"""
"""
An array relationship
"""
quest_roles(
"""distinct select on columns"""
"""
distinct select on columns
"""
distinct_on: [quest_role_select_column!]
"""limit the number of rows returned"""
"""
limit the number of rows returned
"""
limit: Int
"""skip the first n rows. Use only with order_by"""
"""
skip the first n rows. Use only with order_by
"""
offset: Int
"""sort the rows by one or more columns"""
"""
sort the rows by one or more columns
"""
order_by: [quest_role_order_by!]
"""filter the rows returned"""
"""
filter the rows returned
"""
where: quest_role_bool_exp
): [quest_role!]!
"""An aggregated array relationship"""
"""
An aggregated array relationship
"""
quest_roles_aggregate(
"""distinct select on columns"""
"""
distinct select on columns
"""
distinct_on: [quest_role_select_column!]
"""limit the number of rows returned"""
"""
limit the number of rows returned
"""
limit: Int
"""skip the first n rows. Use only with order_by"""
"""
skip the first n rows. Use only with order_by
"""
offset: Int
"""sort the rows by one or more columns"""
"""
sort the rows by one or more columns
"""
order_by: [quest_role_order_by!]
"""filter the rows returned"""
"""
filter the rows returned
"""
where: quest_role_bool_exp
): quest_role_aggregate!
"""An array relationship"""
"""
An array relationship
"""
quest_skills(
"""
distinct select on columns
@@ -10284,10 +10353,14 @@ input quest_pk_columns_input {
columns and relationships of "quest_role"
"""
type quest_role {
"""An object relationship"""
"""
An object relationship
"""
PlayerRole: PlayerRole!
"""An object relationship"""
"""
An object relationship
"""
quest: quest!
quest_id: uuid!
rank: Int!
@@ -10344,7 +10417,9 @@ input quest_role_arr_rel_insert_input {
on_conflict: quest_role_on_conflict
}
"""aggregate avg on columns"""
"""
aggregate avg on columns
"""
type quest_role_avg_fields {
rank: Float
}
@@ -10374,11 +10449,10 @@ input quest_role_bool_exp {
unique or primary key constraints on table "quest_role"
"""
enum quest_role_constraint {
"""unique or primary key constraint"""
"""
unique or primary key constraint
"""
quest_role_pkey
"""unique or primary key constraint"""
quest_role_quest_id_key
}
"""
@@ -10399,7 +10473,9 @@ input quest_role_insert_input {
role: String
}
"""aggregate max on columns"""
"""
aggregate max on columns
"""
type quest_role_max_fields {
quest_id: uuid
rank: Int
@@ -10415,7 +10491,9 @@ input quest_role_max_order_by {
role: order_by
}
"""aggregate min on columns"""
"""
aggregate min on columns
"""
type quest_role_min_fields {
quest_id: uuid
rank: Int
@@ -10435,10 +10513,14 @@ input quest_role_min_order_by {
response of any mutation on the table "quest_role"
"""
type quest_role_mutation_response {
"""number of affected rows by the mutation"""
"""
number of affected rows by the mutation
"""
affected_rows: Int!
"""data of the affected rows by the mutation"""
"""
data of the affected rows by the mutation
"""
returning: [quest_role!]!
}
@@ -10482,13 +10564,19 @@ input quest_role_pk_columns_input {
select columns of table "quest_role"
"""
enum quest_role_select_column {
"""column name"""
"""
column name
"""
quest_id
"""column name"""
"""
column name
"""
rank
"""column name"""
"""
column name
"""
role
}
@@ -10501,7 +10589,9 @@ input quest_role_set_input {
role: String
}
"""aggregate stddev on columns"""
"""
aggregate stddev on columns
"""
type quest_role_stddev_fields {
rank: Float
}
@@ -10513,7 +10603,9 @@ input quest_role_stddev_order_by {
rank: order_by
}
"""aggregate stddev_pop on columns"""
"""
aggregate stddev_pop on columns
"""
type quest_role_stddev_pop_fields {
rank: Float
}
@@ -10525,7 +10617,9 @@ input quest_role_stddev_pop_order_by {
rank: order_by
}
"""aggregate stddev_samp on columns"""
"""
aggregate stddev_samp on columns
"""
type quest_role_stddev_samp_fields {
rank: Float
}
@@ -10537,7 +10631,9 @@ input quest_role_stddev_samp_order_by {
rank: order_by
}
"""aggregate sum on columns"""
"""
aggregate sum on columns
"""
type quest_role_sum_fields {
rank: Int
}
@@ -10553,17 +10649,25 @@ input quest_role_sum_order_by {
update columns of table "quest_role"
"""
enum quest_role_update_column {
"""column name"""
"""
column name
"""
quest_id
"""column name"""
"""
column name
"""
rank
"""column name"""
"""
column name
"""
role
}
"""aggregate var_pop on columns"""
"""
aggregate var_pop on columns
"""
type quest_role_var_pop_fields {
rank: Float
}
@@ -10575,7 +10679,9 @@ input quest_role_var_pop_order_by {
rank: order_by
}
"""aggregate var_samp on columns"""
"""
aggregate var_samp on columns
"""
type quest_role_var_samp_fields {
rank: Float
}
@@ -10587,7 +10693,9 @@ input quest_role_var_samp_order_by {
rank: order_by
}
"""aggregate variance on columns"""
"""
aggregate variance on columns
"""
type quest_role_variance_fields {
rank: Float
}
@@ -13817,19 +13925,29 @@ type subscription_root {
fetch data from the table: "quest_role"
"""
quest_role(
"""distinct select on columns"""
"""
distinct select on columns
"""
distinct_on: [quest_role_select_column!]
"""limit the number of rows returned"""
"""
limit the number of rows returned
"""
limit: Int
"""skip the first n rows. Use only with order_by"""
"""
skip the first n rows. Use only with order_by
"""
offset: Int
"""sort the rows by one or more columns"""
"""
sort the rows by one or more columns
"""
order_by: [quest_role_order_by!]
"""filter the rows returned"""
"""
filter the rows returned
"""
where: quest_role_bool_exp
): [quest_role!]!
@@ -13837,23 +13955,35 @@ type subscription_root {
fetch aggregated fields from the table: "quest_role"
"""
quest_role_aggregate(
"""distinct select on columns"""
"""
distinct select on columns
"""
distinct_on: [quest_role_select_column!]
"""limit the number of rows returned"""
"""
limit the number of rows returned
"""
limit: Int
"""skip the first n rows. Use only with order_by"""
"""
skip the first n rows. Use only with order_by
"""
offset: Int
"""sort the rows by one or more columns"""
"""
sort the rows by one or more columns
"""
order_by: [quest_role_order_by!]
"""filter the rows returned"""
"""
filter the rows returned
"""
where: quest_role_bool_exp
): quest_role_aggregate!
"""fetch data from the table: "quest_role" using primary key columns"""
"""
fetch data from the table: "quest_role" using primary key columns
"""
quest_role_by_pk(quest_id: uuid!, role: String!): quest_role
"""