|
@@ -1,78 +1,84 @@
|
|
import { gql } from "./gql";
|
|
import { gql } from "./gql";
|
|
|
|
|
|
-export const snippetById = async(id) => {
|
|
|
|
- let query = `query snippetFind($query:String){
|
|
|
|
- SnippetFind(query:$query){
|
|
|
|
- owner{
|
|
|
|
- _id
|
|
|
|
- }
|
|
|
|
- title description _id files {
|
|
|
|
- type text name
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }`;
|
|
|
|
- let variables = {
|
|
|
|
- query: JSON.stringify([{_id: id }])
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- let res = gql(query, variables);
|
|
|
|
- return res;
|
|
|
|
- }
|
|
|
|
- export const snippetByOwner = async (id) => {
|
|
|
|
- let query = `query snippetFind($query:String){
|
|
|
|
- SnippetFind(query:$query){
|
|
|
|
- owner{
|
|
|
|
- _id
|
|
|
|
- }
|
|
|
|
- title description _id files {
|
|
|
|
- type text name
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }`;
|
|
|
|
- let variables = {
|
|
|
|
- query: JSON.stringify([{___owner: id } , {sort:[{_id: -1}]}])
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- let res = gql(query, variables);
|
|
|
|
- return res;
|
|
|
|
- }
|
|
|
|
- export const userFind = (_id) => {
|
|
|
|
- return gql(
|
|
|
|
- `query userOne($query:String) {
|
|
|
|
- UserFindOne(query:$query){
|
|
|
|
- _id avatar{
|
|
|
|
- url
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }`,
|
|
|
|
- { query: JSON.stringify([{ _id }]) }
|
|
|
|
|
|
+
|
|
|
|
+export const userFind = (_id) => {
|
|
|
|
+ return gql(`query userOne($query:String) {
|
|
|
|
+ UserFindOne(query:$query){
|
|
|
|
+ _id
|
|
|
|
+ avatar{
|
|
|
|
+ url
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`,
|
|
|
|
+ { query: JSON.stringify([{ _id }]) }
|
|
);
|
|
);
|
|
- };
|
|
|
|
- export const reg = async (login, password) => {
|
|
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const reg = async (login, password) => {
|
|
let query = `mutation reg($l:String! , $p:String!) {
|
|
let query = `mutation reg($l:String! , $p:String!) {
|
|
createUser(login:$l,password:$p){
|
|
createUser(login:$l,password:$p){
|
|
- _id login
|
|
|
|
- }
|
|
|
|
- }`;
|
|
|
|
|
|
+ _id login
|
|
|
|
+ }
|
|
|
|
+ }`;
|
|
let qVariables = {
|
|
let qVariables = {
|
|
- l: login,
|
|
|
|
- p: password,
|
|
|
|
|
|
+ l: login,
|
|
|
|
+ p: password
|
|
};
|
|
};
|
|
let result = await gql(query, qVariables);
|
|
let result = await gql(query, qVariables);
|
|
return result;
|
|
return result;
|
|
- };
|
|
|
|
- export const log = async (login, password) => {
|
|
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const log = async (login, password) => {
|
|
let query = ` query log($l:String!,$p:String!) {
|
|
let query = ` query log($l:String!,$p:String!) {
|
|
login(login:$l,password:$p)
|
|
login(login:$l,password:$p)
|
|
}`;
|
|
}`;
|
|
let qVariables = {
|
|
let qVariables = {
|
|
l: login,
|
|
l: login,
|
|
- p: password,
|
|
|
|
|
|
+ p: password
|
|
};
|
|
};
|
|
let result = await gql(query, qVariables);
|
|
let result = await gql(query, qVariables);
|
|
return result;
|
|
return result;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const search = async (string) => {
|
|
|
|
+ return gql(`query snippetFind($query:String){
|
|
|
|
+ SnippetFind(query:$query){
|
|
|
|
+ owner {
|
|
|
|
+ _id login
|
|
|
|
+ }
|
|
|
|
+ title description _id files {
|
|
|
|
+ type text name
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`,
|
|
|
|
+ { query: JSON.stringify([
|
|
|
|
+ {
|
|
|
|
+ $or: [{title: `/${string.trim().split(" ").join('|')}/`},{description: `/${string.trim().split(" ").join('|')}/`}]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ sort: [{title: 1}]}]) }
|
|
|
|
+ );
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const snippetByOwner = async (id) => {
|
|
|
|
+ let query = `query snippetFind($query:String){
|
|
|
|
+ SnippetFind(query:$query){
|
|
|
|
+ owner{
|
|
|
|
+ _id
|
|
|
|
+ }
|
|
|
|
+ title description _id files {
|
|
|
|
+ type text name
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`;
|
|
|
|
+ let variables = {
|
|
|
|
+ query: JSON.stringify([{___owner: id } , {sort:[{_id: -1}]}])
|
|
};
|
|
};
|
|
- export const imgFind = async () => {
|
|
|
|
|
|
+ let res = gql(query, variables);
|
|
|
|
+ return res;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export const imgFind = async () => {
|
|
return await gql(`query fhbg{
|
|
return await gql(`query fhbg{
|
|
ImageFind(query:"[{}]"){
|
|
ImageFind(query:"[{}]"){
|
|
url owner{
|
|
url owner{
|
|
@@ -80,8 +86,9 @@ export const snippetById = async(id) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`);
|
|
}`);
|
|
- };
|
|
|
|
- export const ava = async (idUser, id) => {
|
|
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const ava = async (idUser, id) => {
|
|
let query = `mutation setAvatar($idUser:String , $idAvatar:ID){
|
|
let query = `mutation setAvatar($idUser:String , $idAvatar:ID){
|
|
UserUpsert(user:{_id: $idUser, avatar: {_id: $idAvatar}}){
|
|
UserUpsert(user:{_id: $idUser, avatar: {_id: $idAvatar}}){
|
|
_id, avatar{
|
|
_id, avatar{
|
|
@@ -89,43 +96,67 @@ export const snippetById = async(id) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`;
|
|
}`;
|
|
- let qVariables = { idUser: idUser, idAvatar: id };
|
|
|
|
-
|
|
|
|
|
|
+ let qVariables = {
|
|
|
|
+ idUser: idUser,
|
|
|
|
+ idAvatar: id
|
|
|
|
+ };
|
|
let res = await gql(query, qVariables);
|
|
let res = await gql(query, qVariables);
|
|
return res;
|
|
return res;
|
|
- };
|
|
|
|
- export const snippetAdd = async (title, description, files , idSnippet) => {
|
|
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const snippetAdd = async (title, description, files , idSnippet) => {
|
|
let query = `mutation newSnippet($snippet:SnippetInput) {
|
|
let query = `mutation newSnippet($snippet:SnippetInput) {
|
|
SnippetUpsert(snippet:$snippet){
|
|
SnippetUpsert(snippet:$snippet){
|
|
_id
|
|
_id
|
|
}
|
|
}
|
|
}`;
|
|
}`;
|
|
-
|
|
|
|
- let qVariables = { snippet: { title, description, files, _id: idSnippet } };
|
|
|
|
-
|
|
|
|
|
|
+ let qVariables = {
|
|
|
|
+ snippet:{
|
|
|
|
+ title,
|
|
|
|
+ description,
|
|
|
|
+ files,
|
|
|
|
+ _id: idSnippet
|
|
|
|
+ }
|
|
|
|
+ };
|
|
let res = await gql(query, qVariables);
|
|
let res = await gql(query, qVariables);
|
|
return res;
|
|
return res;
|
|
- };
|
|
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const changePass = async (login, password, newPassword) => {
|
|
|
|
+ let query = `mutation change($login:String!, $password:String!, $newPassword:String!){
|
|
|
|
+ changePassword(login: $login,
|
|
|
|
+ password: $password,
|
|
|
|
+ newPassword: $newPassword){
|
|
|
|
+ _id login
|
|
|
|
+ }
|
|
|
|
+ }`;
|
|
|
|
+ let qVariables = {
|
|
|
|
+ l:login,
|
|
|
|
+ p:password,
|
|
|
|
+ n:newPassword
|
|
|
|
+ };
|
|
|
|
+ let result = await gql(query, qVariables);
|
|
|
|
+ return result;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+export const snippetById = async(id) => {
|
|
|
|
+ let query = `query snippetFind($query:String){
|
|
|
|
+ SnippetFind(query:$query){
|
|
|
|
+ owner{
|
|
|
|
+ _id
|
|
|
|
+ }
|
|
|
|
+ title description _id files {
|
|
|
|
+ type text name
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`;
|
|
|
|
+ let variables = {
|
|
|
|
+ query: JSON.stringify([{_id: id }])
|
|
|
|
+ };
|
|
|
|
+ let res = gql(query, variables);
|
|
|
|
+ return res;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
- export const search = async (string) => {
|
|
|
|
- return gql(
|
|
|
|
- `query snippetFind($query:String){
|
|
|
|
- SnippetFind(query:$query){
|
|
|
|
- owner {
|
|
|
|
- _id login
|
|
|
|
- }
|
|
|
|
- title description _id files {
|
|
|
|
- type text name
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }`,
|
|
|
|
- { query: JSON.stringify([
|
|
|
|
- {
|
|
|
|
- $or: [{title: `/${string.trim().split(" ").join('|')}/`},{description: `/${string.trim().split(" ").join('|')}/`}]
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- sort: [{title: 1}]}]) }
|
|
|
|
- );
|
|
|
|
- };
|
|
|
|
|
|
|
|
|
|
|