feat: Support invites in CLI for V2 (#6798)

**What**

- Add invite support to cli for 2.0
- Allow email to be passed upon accepting an invite
This commit is contained in:
Oli Juhl
2024-03-26 20:02:56 +00:00
committed by GitHub
parent 16860cc883
commit 0b23e7efb8
8 changed files with 98 additions and 85 deletions
@@ -1,11 +1,10 @@
import { acceptInviteWorkflow } from "@medusajs/core-flows"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IUserModuleService, InviteWorkflow } from "@medusajs/types"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../../types/routing"
import { acceptInviteWorkflow } from "@medusajs/core-flows"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import { IUserModuleService, InviteWorkflow } from "@medusajs/types"
import { AdminPostInvitesInviteAcceptReq } from "../validators"
export const POST = async (
@@ -21,8 +20,6 @@ export const POST = async (
return
}
const workflow = acceptInviteWorkflow(req.scope)
const input = {
invite_token: req.filterableFields.token as string,
auth_user_id: req.auth?.auth_user_id,
@@ -31,7 +28,7 @@ export const POST = async (
let users
try {
const { result } = await workflow.run({ input })
const { result } = await acceptInviteWorkflow(req.scope).run({ input })
users = result
} catch (e) {
res.status(401).json({ message: "Unauthorized" })
@@ -77,11 +77,6 @@ export class AdminCreateInviteRequest {
email: string
}
/**
* Details of the use accepting the invite.
*/
export class AdminPostInvitesInviteAcceptUserReq {}
/**
* @schema AdminPostInvitesInviteAcceptReq
* type: object
@@ -113,6 +108,13 @@ export class AdminPostInvitesInviteAcceptUserReq {}
* format: password
*/
export class AdminPostInvitesInviteAcceptReq {
/**
* The invite's first name.
* If email is not passed, we default to using the email of the invite.
*/
@IsString()
@IsOptional()
email: string
/**
* The invite's first name.
*/