chore: Rename credentials as connections
This commit is contained in:
@@ -4,18 +4,18 @@ import Field from '../../types/field';
|
|||||||
|
|
||||||
export default class Twitter {
|
export default class Twitter {
|
||||||
client: any
|
client: any
|
||||||
credentialsData: any
|
connectionData: any
|
||||||
appData: any
|
appData: any
|
||||||
|
|
||||||
constructor(credentialsData: any) {
|
constructor(connectionData: any) {
|
||||||
this.client = new TwitterApi({
|
this.client = new TwitterApi({
|
||||||
appKey: credentialsData.consumerKey,
|
appKey: connectionData.consumerKey,
|
||||||
appSecret: credentialsData.consumerSecret,
|
appSecret: connectionData.consumerSecret,
|
||||||
accessToken: credentialsData.accessToken,
|
accessToken: connectionData.accessToken,
|
||||||
accessSecret: credentialsData.accessSecret
|
accessSecret: connectionData.accessSecret
|
||||||
});
|
});
|
||||||
|
|
||||||
this.credentialsData = credentialsData;
|
this.connectionData = connectionData;
|
||||||
this.appData = App.findOneByName('twitter');
|
this.appData = App.findOneByName('twitter');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,11 +27,11 @@ export default class Twitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async verifyCredentials() {
|
async verifyCredentials() {
|
||||||
const verifiedCredentials = await this.client.login(this.credentialsData.oauthVerifier)
|
const verifiedCredentials = await this.client.login(this.connectionData.oauthVerifier)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
consumerKey: this.credentialsData.consumerKey,
|
consumerKey: this.connectionData.consumerKey,
|
||||||
consumerSecret: this.credentialsData.consumerSecret,
|
consumerSecret: this.connectionData.consumerSecret,
|
||||||
accessToken: verifiedCredentials.accessToken,
|
accessToken: verifiedCredentials.accessToken,
|
||||||
accessSecret: verifiedCredentials.accessSecret,
|
accessSecret: verifiedCredentials.accessSecret,
|
||||||
userId: verifiedCredentials.userId,
|
userId: verifiedCredentials.userId,
|
||||||
|
@@ -47,7 +47,7 @@
|
|||||||
{
|
{
|
||||||
"step": 1,
|
"step": 1,
|
||||||
"type": "mutation",
|
"type": "mutation",
|
||||||
"name": "createCredential",
|
"name": "createConnection",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "key",
|
"name": "key",
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"value": "{createCredential.id}"
|
"value": "{createConnection.id}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -94,11 +94,11 @@
|
|||||||
{
|
{
|
||||||
"step": 4,
|
"step": 4,
|
||||||
"type": "mutation",
|
"type": "mutation",
|
||||||
"name": "updateCredential",
|
"name": "updateConnection",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"value": "{createCredential.id}"
|
"value": "{createConnection.id}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "data",
|
"name": "data",
|
||||||
|
@@ -0,0 +1,9 @@
|
|||||||
|
import { Knex } from "knex";
|
||||||
|
|
||||||
|
export async function up(knex: Knex): Promise<void> {
|
||||||
|
return knex.schema.renameTable('credentials', 'connections');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(knex: Knex): Promise<void> {
|
||||||
|
return knex.schema.renameTable('connections', 'credentials');
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
import { GraphQLNonNull, GraphQLString } from 'graphql';
|
||||||
import Credential from '../../models/credential';
|
import Connection from '../../models/connection';
|
||||||
import authLinkType from '../types/auth-link';
|
import authLinkType from '../types/auth-link';
|
||||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
@@ -7,19 +7,19 @@ type Params = {
|
|||||||
id: number,
|
id: number,
|
||||||
}
|
}
|
||||||
const createAuthLinkResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
const createAuthLinkResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
const credential = await Credential.query().findOne({
|
const connection = await Connection.query().findOne({
|
||||||
user_id: req.currentUser.id,
|
user_id: req.currentUser.id,
|
||||||
id: params.id
|
id: params.id
|
||||||
})
|
})
|
||||||
|
|
||||||
const appClass = (await import(`../../apps/${credential.key}`)).default;
|
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||||
|
|
||||||
const appInstance = new appClass(credential.data)
|
const appInstance = new appClass(connection.data)
|
||||||
const authLink = await appInstance.createAuthLink();
|
const authLink = await appInstance.createAuthLink();
|
||||||
|
|
||||||
await credential.$query().patch({
|
await connection.$query().patch({
|
||||||
data: {
|
data: {
|
||||||
...credential.data,
|
...connection.data,
|
||||||
url: authLink.url,
|
url: authLink.url,
|
||||||
accessToken: authLink.oauth_token,
|
accessToken: authLink.oauth_token,
|
||||||
accessSecret: authLink.oauth_token_secret,
|
accessSecret: authLink.oauth_token_secret,
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
import Credential from '../../models/credential';
|
import Connection from '../../models/connection';
|
||||||
import credentialType from '../types/credential';
|
import connectionType from '../types/connection';
|
||||||
import twitterCredentialInputType from '../types/twitter-credential-input';
|
import twitterCredentialInputType from '../types/twitter-credential-input';
|
||||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
@@ -8,23 +8,23 @@ type Params = {
|
|||||||
key: string,
|
key: string,
|
||||||
data: object
|
data: object
|
||||||
}
|
}
|
||||||
const createCredentialResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
const createConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
const credential = await Credential.query().insert({
|
const connection = await Connection.query().insert({
|
||||||
key: params.key,
|
key: params.key,
|
||||||
data: params.data,
|
data: params.data,
|
||||||
userId: req.currentUser.id
|
userId: req.currentUser.id
|
||||||
});
|
});
|
||||||
|
|
||||||
return credential;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createCredential = {
|
const createConnection = {
|
||||||
type: credentialType,
|
type: connectionType,
|
||||||
args: {
|
args: {
|
||||||
key: { type: GraphQLNonNull(GraphQLString) },
|
key: { type: GraphQLNonNull(GraphQLString) },
|
||||||
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
||||||
},
|
},
|
||||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createCredentialResolver(params, req)
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createConnectionResolver(params, req)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createCredential;
|
export default createConnection;
|
@@ -1,6 +1,6 @@
|
|||||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||||
import Credential from '../../models/credential';
|
import Connection from '../../models/connection';
|
||||||
import credentialType from '../types/credential';
|
import connectionType from '../types/connection';
|
||||||
import twitterCredentialInputType from '../types/twitter-credential-input';
|
import twitterCredentialInputType from '../types/twitter-credential-input';
|
||||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||||
|
|
||||||
@@ -8,38 +8,38 @@ type Params = {
|
|||||||
id: string,
|
id: string,
|
||||||
data: object
|
data: object
|
||||||
}
|
}
|
||||||
const updateCredentialResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
const updateConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
let credential = await Credential.query().findOne({
|
let connection = await Connection.query().findOne({
|
||||||
user_id: req.currentUser.id,
|
user_id: req.currentUser.id,
|
||||||
id: params.id
|
id: params.id
|
||||||
})
|
})
|
||||||
|
|
||||||
credential = await credential.$query().patchAndFetch({
|
connection = await connection.$query().patchAndFetch({
|
||||||
data: {
|
data: {
|
||||||
...credential.data,
|
...connection.data,
|
||||||
...params.data
|
...params.data
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const appClass = (await import(`../../apps/${credential.key}`)).default;
|
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||||
|
|
||||||
const appInstance = new appClass(credential.data)
|
const appInstance = new appClass(connection.data)
|
||||||
const verifiedCredentials = await appInstance.verifyCredentials();
|
const verifiedCredentials = await appInstance.verifyCredentials();
|
||||||
|
|
||||||
credential = await credential.$query().patchAndFetch({
|
connection = await connection.$query().patchAndFetch({
|
||||||
data: verifiedCredentials
|
data: verifiedCredentials
|
||||||
})
|
})
|
||||||
|
|
||||||
return credential;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateCredential = {
|
const updateConnection = {
|
||||||
type: credentialType,
|
type: connectionType,
|
||||||
args: {
|
args: {
|
||||||
id: { type: GraphQLNonNull(GraphQLString) },
|
id: { type: GraphQLNonNull(GraphQLString) },
|
||||||
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
data: { type: GraphQLNonNull(twitterCredentialInputType) }
|
||||||
},
|
},
|
||||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateCredentialResolver(params, req)
|
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => updateConnectionResolver(params, req)
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateCredential;
|
export default updateConnection;
|
@@ -1,14 +1,14 @@
|
|||||||
import { GraphQLObjectType } from 'graphql';
|
import { GraphQLObjectType } from 'graphql';
|
||||||
import createCredential from './mutations/create-credential';
|
import createConnection from './mutations/create-connection';
|
||||||
import createAuthLink from './mutations/create-auth-link';
|
import createAuthLink from './mutations/create-auth-link';
|
||||||
import updateCredential from './mutations/update-credential';
|
import updateConnection from './mutations/update-connection';
|
||||||
|
|
||||||
const rootMutation = new GraphQLObjectType({
|
const rootMutation = new GraphQLObjectType({
|
||||||
name: 'Mutation',
|
name: 'Mutation',
|
||||||
fields: {
|
fields: {
|
||||||
createCredential: createCredential,
|
createConnection: createConnection,
|
||||||
createAuthLink: createAuthLink,
|
createAuthLink: createAuthLink,
|
||||||
updateCredential: updateCredential
|
updateConnection: updateConnection
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { GraphQLObjectType, GraphQLString, GraphQLBoolean } from 'graphql';
|
import { GraphQLObjectType, GraphQLString, GraphQLBoolean } from 'graphql';
|
||||||
import twitterCredentialType from './twitter-credential';
|
import twitterCredentialType from './twitter-credential';
|
||||||
|
|
||||||
const credentialType = new GraphQLObjectType({
|
const connectionType = new GraphQLObjectType({
|
||||||
name: 'credential',
|
name: 'connection',
|
||||||
fields: {
|
fields: {
|
||||||
id: { type: GraphQLString },
|
id: { type: GraphQLString },
|
||||||
key: { type: GraphQLString },
|
key: { type: GraphQLString },
|
||||||
@@ -11,4 +11,4 @@ const credentialType = new GraphQLObjectType({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export default credentialType;
|
export default connectionType;
|
@@ -1,14 +1,14 @@
|
|||||||
import Base from './base'
|
import Base from './base'
|
||||||
import User from './user'
|
import User from './user'
|
||||||
|
|
||||||
class Credential extends Base {
|
class Connection extends Base {
|
||||||
id!: number
|
id!: number
|
||||||
key!: string
|
key!: string
|
||||||
data!: any
|
data!: any
|
||||||
userId!: number
|
userId!: number
|
||||||
verified: boolean
|
verified: boolean
|
||||||
|
|
||||||
static tableName = 'credentials';
|
static tableName = 'connections';
|
||||||
|
|
||||||
static jsonSchema = {
|
static jsonSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@@ -24,15 +24,15 @@ class Credential extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static relationMappings = () => ({
|
static relationMappings = () => ({
|
||||||
credentials: {
|
user: {
|
||||||
relation: Base.BelongsToOneRelation,
|
relation: Base.BelongsToOneRelation,
|
||||||
modelClass: User,
|
modelClass: User,
|
||||||
join: {
|
join: {
|
||||||
from: 'credentials.user_id',
|
from: 'connections.user_id',
|
||||||
to: 'users.id',
|
to: 'users.id',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Credential;
|
export default Connection;
|
@@ -1,6 +1,6 @@
|
|||||||
import { QueryContext, ModelOptions } from 'objection';
|
import { QueryContext, ModelOptions } from 'objection';
|
||||||
import Base from './base';
|
import Base from './base';
|
||||||
import Credential from './credential';
|
import Connection from './connection';
|
||||||
import bcrypt from 'bcrypt';
|
import bcrypt from 'bcrypt';
|
||||||
|
|
||||||
class User extends Base {
|
class User extends Base {
|
||||||
@@ -22,12 +22,12 @@ class User extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static relationMappings = () => ({
|
static relationMappings = () => ({
|
||||||
credentials: {
|
connections: {
|
||||||
relation: Base.HasManyRelation,
|
relation: Base.HasManyRelation,
|
||||||
modelClass: Credential,
|
modelClass: Connection,
|
||||||
join: {
|
join: {
|
||||||
from: 'users.id',
|
from: 'users.id',
|
||||||
to: 'credentials.user_id',
|
to: 'connections.user_id',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user