-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
158 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { FieldResolveInput } from 'stucco-js'; | ||
import { orm } from '../db/orm.js'; | ||
import { EditUserError, resolverFor } from '../zeus/index.js'; | ||
|
||
export const handler = async (input: FieldResolveInput) => | ||
resolverFor('Mutation', 'editUser', async ({ updatedUser }) => { | ||
const o = await orm(); | ||
const { userId, username, fullName } = updatedUser; | ||
const userCollection = o('UserCollection').collection; | ||
|
||
const user = await userCollection.findOne({ userId }); | ||
if (!user) { | ||
return { hasError: EditUserError.USER_DOES_NOT_EXIST }; | ||
} | ||
|
||
if (username !== undefined && username !== null) { | ||
const existingUser = await userCollection.findOne({ username, userId: { $ne: userId } }); | ||
if (existingUser) { | ||
return { hasError: EditUserError.USERNAME_ALREADY_TAKEN }; | ||
} | ||
} | ||
const update: any = {}; | ||
if (username !== undefined && username !== null) { | ||
update.username = username; | ||
} | ||
if (fullName !== undefined && fullName !== null) { | ||
update.fullName = fullName; | ||
} | ||
|
||
const res = await userCollection.updateOne({ userId }, { $set: update }); | ||
if (res.modifiedCount === 0) { | ||
return { hasError: EditUserError.FAILED_MONGO_UPDATE }; | ||
} | ||
})(input.arguments); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/integrations/gei-users/src/models/EditUserResponseModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ModelTypes } from '../zeus/index.js'; | ||
|
||
export type EditUserResponseModel = ModelTypes['EditUserResponse']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.