|
@@ -1,150 +1,136 @@
|
|
import { gql } from "./gql";
|
|
import { gql } from "./gql";
|
|
|
|
|
|
-export const log = async (login, password) => {
|
|
|
|
- let query = `query login($login:String!, $password:String!) {
|
|
|
|
- login(
|
|
|
|
- login: $login,
|
|
|
|
- password: $password
|
|
|
|
- )}`;
|
|
|
|
-
|
|
|
|
- let variables = { login, password };
|
|
|
|
-
|
|
|
|
- let token = await gql(query, variables);
|
|
|
|
|
|
+export const login = async (_login, password) => {
|
|
|
|
+ const query = `query login($login:String!, $password:String!) {
|
|
|
|
+ login(
|
|
|
|
+ login: $login,
|
|
|
|
+ password: $password
|
|
|
|
+ )
|
|
|
|
+ }`;
|
|
|
|
+
|
|
|
|
+ const token = await gql(query, { login: _login, password });
|
|
localStorage.authToken = token.data.login;
|
|
localStorage.authToken = token.data.login;
|
|
|
|
+
|
|
console.log(token);
|
|
console.log(token);
|
|
return token.data.login;
|
|
return token.data.login;
|
|
};
|
|
};
|
|
|
|
|
|
-export const reg = async (login, password) => {
|
|
|
|
- let query = `mutation reg($login:String!, $password:String!) {
|
|
|
|
- createUser(
|
|
|
|
- login: $login,
|
|
|
|
- password: $password
|
|
|
|
|
|
+export const registration = async (login, password) => {
|
|
|
|
+ const query = `mutation reg($login:String!, $password:String!) {
|
|
|
|
+ createUser(
|
|
|
|
+ login: $login,
|
|
|
|
+ password: $password
|
|
|
|
+ ){
|
|
|
|
+ _id
|
|
|
|
+ }
|
|
|
|
+ }`;
|
|
|
|
|
|
- ){
|
|
|
|
- _id
|
|
|
|
- }}`;
|
|
|
|
|
|
+ return await gql(query, { login, password });
|
|
|
|
+};
|
|
|
|
|
|
- let variables = { login: login, password: password };
|
|
|
|
|
|
+export const findImage = async () => {
|
|
|
|
+ const query = `query imgFind {
|
|
|
|
+ ImageFind(query:"[{}]") {
|
|
|
|
+ url owner{
|
|
|
|
+ nick
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`;
|
|
|
|
|
|
- let res = await gql(query, variables);
|
|
|
|
- return res;
|
|
|
|
|
|
+ return await gql(query);
|
|
};
|
|
};
|
|
|
|
|
|
-export const imgFind = async () => {
|
|
|
|
- return await gql(`query imgFind{
|
|
|
|
- ImageFind(query:"[{}]"){
|
|
|
|
- url owner{
|
|
|
|
- nick
|
|
|
|
- }
|
|
|
|
|
|
+export const findUser = async _id => {
|
|
|
|
+ const query = `query userOne($query:String) {
|
|
|
|
+ UserFindOne(query:$query) {
|
|
|
|
+ _id avatar{
|
|
|
|
+ url
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }`);
|
|
|
|
-};
|
|
|
|
|
|
+ }`;
|
|
|
|
|
|
-export const userFind = _id => {
|
|
|
|
- return gql(
|
|
|
|
- `query userOne($query:String) {
|
|
|
|
- UserFindOne(query:$query){
|
|
|
|
- _id avatar{
|
|
|
|
- url
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }`,
|
|
|
|
- { query: JSON.stringify([{ _id }]) },
|
|
|
|
- );
|
|
|
|
|
|
+ return await gql(query, { query: JSON.stringify([{ _id }]) });
|
|
};
|
|
};
|
|
|
|
|
|
-export const setAva = async (idUser, id) => {
|
|
|
|
- let query = `mutation setAvatar($idUser:String , $idAvatar:ID){
|
|
|
|
- UserUpsert(user:{_id: $idUser, avatar: {_id: $idAvatar}}){
|
|
|
|
- _id, avatar{
|
|
|
|
- url
|
|
|
|
- }
|
|
|
|
|
|
+export const setAvatar = async (idUser, idAvatar) => {
|
|
|
|
+ const query = `mutation setAvatar($idUser:String , $idAvatar:ID) {
|
|
|
|
+ UserUpsert(user:{_id: $idUser, avatar: {_id: $idAvatar}}) {
|
|
|
|
+ _id, avatar{
|
|
|
|
+ url
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }`;
|
|
|
|
-
|
|
|
|
- let variables = { idUser: idUser, idAvatar: id };
|
|
|
|
|
|
+ }`;
|
|
|
|
|
|
- let res = await gql(query, variables);
|
|
|
|
- return res;
|
|
|
|
|
|
+ return await gql(query, { idUser, idAvatar });
|
|
};
|
|
};
|
|
|
|
|
|
-export const snippetAdd = async (title, description, files, idSnippet) => {
|
|
|
|
- let query = `mutation newSnippet($snippet:SnippetInput) {
|
|
|
|
|
|
+export const addSnippet = async (title, description, files, idSnippet) => {
|
|
|
|
+ const query = `mutation newSnippet($snippet:SnippetInput) {
|
|
SnippetUpsert(snippet:$snippet){
|
|
SnippetUpsert(snippet:$snippet){
|
|
_id
|
|
_id
|
|
}
|
|
}
|
|
- }`;
|
|
|
|
|
|
+ }`;
|
|
|
|
|
|
- let qVariables = { snippet: { title, description, files, _id: idSnippet } };
|
|
|
|
-
|
|
|
|
- let res = await gql(query, qVariables);
|
|
|
|
- return res;
|
|
|
|
|
|
+ return await gql(query, {
|
|
|
|
+ snippet: { title, description, files, _id: idSnippet },
|
|
|
|
+ });
|
|
};
|
|
};
|
|
|
|
|
|
-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 getSnippetById = async id => {
|
|
|
|
+ const query = `query snippetFind($query:String) {
|
|
|
|
+ SnippetFind(query:$query) {
|
|
|
|
+ owner{
|
|
|
|
+ _id
|
|
|
|
+ }
|
|
|
|
+ title description _id files {
|
|
|
|
+ type text name
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`;
|
|
|
|
+
|
|
|
|
+ return await gql(query, { query: JSON.stringify([{ _id: id }]) });
|
|
};
|
|
};
|
|
|
|
|
|
-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 getSnippetByOwnerId = async id => {
|
|
|
|
+ const query = `query snippetFind($query:String) {
|
|
|
|
+ SnippetFind(query:$query) {
|
|
|
|
+ owner{
|
|
|
|
+ _id
|
|
|
|
+ }
|
|
|
|
+ title description _id files {
|
|
|
|
+ type text name
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`;
|
|
|
|
|
|
- let res = gql(query, variables);
|
|
|
|
- return res;
|
|
|
|
|
|
+ return await gql(query, {
|
|
|
|
+ query: JSON.stringify([{ ___owner: id }, { sort: [{ _id: -1 }] }]),
|
|
|
|
+ });
|
|
};
|
|
};
|
|
|
|
|
|
export const search = async string => {
|
|
export const search = async string => {
|
|
- return gql(
|
|
|
|
- `query snippetFind($query:String){
|
|
|
|
- SnippetFind(query:$query){
|
|
|
|
- owner {
|
|
|
|
|
|
+ const query = `query snippetFind($query:String) {
|
|
|
|
+ SnippetFind(query:$query) {
|
|
|
|
+ owner {
|
|
_id login
|
|
_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 }],
|
|
|
|
- },
|
|
|
|
- ]),
|
|
|
|
- },
|
|
|
|
- );
|
|
|
|
|
|
+ }
|
|
|
|
+ title description _id files {
|
|
|
|
+ type text name
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }`;
|
|
|
|
+
|
|
|
|
+ return await gql(query, {
|
|
|
|
+ query: JSON.stringify([
|
|
|
|
+ {
|
|
|
|
+ $or: [
|
|
|
|
+ { title: `/${string.trim().split(" ").join("|")}/` },
|
|
|
|
+ { description: `/${string.trim().split(" ").join("|")}/` },
|
|
|
|
+ ],
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ sort: [{ title: 1 }],
|
|
|
|
+ },
|
|
|
|
+ ]),
|
|
|
|
+ });
|
|
};
|
|
};
|