feat: Introduce reset and verify connection mutations
This commit is contained in:
31
packages/backend/src/graphql/mutations/reset-connection.ts
Normal file
31
packages/backend/src/graphql/mutations/reset-connection.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Connection from '../../models/connection';
|
||||
import connectionType from '../types/connection';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
|
||||
type Params = {
|
||||
id: string
|
||||
}
|
||||
|
||||
const resetConnectionResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
let connection = await Connection.query().findOne({
|
||||
user_id: req.currentUser.id,
|
||||
id: params.id
|
||||
})
|
||||
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: { screenName: connection.data.screenName }
|
||||
})
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
const resetConnection = {
|
||||
type: connectionType,
|
||||
args: {
|
||||
id: { type: GraphQLNonNull(GraphQLString) },
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => resetConnectionResolver(params, req)
|
||||
};
|
||||
|
||||
export default resetConnection;
|
Reference in New Issue
Block a user