Add create organization

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-02-26 10:05:56 +01:00
parent 3ee3b37dac
commit b8eb0198db
19 changed files with 2213 additions and 389 deletions

View File

@@ -33,12 +33,15 @@ const VendorOverviewPage = lazy(() => import("./pages/VendorOverviewPage"));
const SettingsPage = lazy(() => import("./pages/SettingsPage"));
const CreatePeoplePage = lazy(() => import("./pages/CreatePeoplePage"));
const FrameworkOverviewPage = lazy(
() => import("./pages/FrameworkOverviewPage"),
() => import("./pages/FrameworkOverviewPage")
);
const ControlOverviewPage = lazy(() => import("./pages/ControlOverviewPage"));
const PeopleOverviewPage = lazy(() => import("./pages/PeopleOverviewPage"));
const LoginPage = lazy(() => import("./pages/LoginPage"));
const RegisterPage = lazy(() => import("./pages/RegisterPage"));
const CreateOrganizationPage = lazy(
() => import("./pages/CreateOrganizationPage")
);
function App() {
return (
@@ -202,6 +205,16 @@ function App() {
</Suspense>
}
/>
<Route
path="organizations/create"
element={
<Suspense>
<ErrorBoundaryWithLocation>
<CreateOrganizationPage />
</ErrorBoundaryWithLocation>
</Suspense>
}
/>
<Route
path="*"
element={

View File

@@ -4,6 +4,7 @@ import { useState, useEffect } from "react";
import { ChevronsUpDown, Plus } from "lucide-react";
import { graphql, useFragment } from "react-relay";
import { useOrganization } from "@/contexts/OrganizationContext";
import { Link } from "react-router";
import {
DropdownMenu,
@@ -27,18 +28,24 @@ import {
export const teamSwitcherFragment = graphql`
fragment TeamSwitcher_organizations on User {
organizations {
id
name
logoUrl
organizations(first: 25) @connection(key: "TeamSwitcher_organizations") {
__id
edges {
node {
id
name
logoUrl
}
}
}
}
`;
// Extended type to include plan field until Relay compiler generates the types
type Organization = TeamSwitcher_organizations$data["organizations"][0] & {
plan?: string;
};
type Organization =
TeamSwitcher_organizations$data["organizations"]["edges"][0]["node"] & {
plan?: string;
};
export function TeamSwitcher({
organizations,
@@ -50,13 +57,15 @@ export function TeamSwitcher({
const { currentOrganization, setCurrentOrganization } = useOrganization();
useEffect(() => {
console.log(data.organizations);
if (
data.organizations &&
data.organizations.length > 0 &&
data.organizations.edges.length > 0 &&
!currentOrganization
) {
// Type assertion to include plan field
setCurrentOrganization(data.organizations[0] as Organization);
setCurrentOrganization(data.organizations.edges[0].node);
}
}, [data.organizations, currentOrganization, setCurrentOrganization]);
@@ -109,27 +118,32 @@ export function TeamSwitcher({
<DropdownMenuLabel className="text-xs text-muted-foreground">
Organizations
</DropdownMenuLabel>
{data.organizations.map((org: Organization, index: number) => (
{data.organizations.edges.map((edge, index) => (
<DropdownMenuItem
key={org.id}
onClick={() => setCurrentOrganization(org)}
key={edge.node.id}
onClick={() => setCurrentOrganization(edge.node)}
className="gap-2 p-2"
>
<div className="flex size-6 items-center justify-center rounded-sm border">
<LogoComponent org={org} className="size-4 shrink-0" />
<LogoComponent org={edge.node} className="size-4 shrink-0" />
</div>
{org.name}
{edge.node.name}
<DropdownMenuShortcut>⌘{index + 1}</DropdownMenuShortcut>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuItem className="gap-2 p-2">
<div className="flex size-6 items-center justify-center rounded-md border bg-background">
<Plus className="size-4" />
</div>
<div className="font-medium text-muted-foreground">
Add organization
</div>
<DropdownMenuItem asChild>
<Link
to="/organizations/create"
className="gap-2 p-2 cursor-pointer"
>
<div className="flex size-6 items-center justify-center rounded-md border bg-background">
<Plus className="size-4" />
</div>
<div className="font-medium text-muted-foreground">
Add organization
</div>
</Link>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<d060c85c907876f442133c643b917eee>>
* @generated SignedSource<<a1cc304a7eb154a19a1ec9a68c2cda98>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -29,7 +29,14 @@ var v0 = {
"kind": "ScalarField",
"name": "id",
"storageKey": null
};
},
v1 = [
{
"kind": "Literal",
"name": "first",
"value": 25
}
];
return {
"fragment": {
"argumentDefinitions": [],
@@ -80,29 +87,111 @@ return {
(v0/*: any*/),
{
"alias": null,
"args": null,
"concreteType": "Organization",
"args": (v1/*: any*/),
"concreteType": "OrganizationConnection",
"kind": "LinkedField",
"name": "organizations",
"plural": true,
"plural": false,
"selections": [
(v0/*: any*/),
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"concreteType": "OrganizationEdge",
"kind": "LinkedField",
"name": "edges",
"plural": true,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Organization",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
(v0/*: any*/),
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "logoUrl",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "__typename",
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "cursor",
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "logoUrl",
"concreteType": "PageInfo",
"kind": "LinkedField",
"name": "pageInfo",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "endCursor",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "hasNextPage",
"storageKey": null
}
],
"storageKey": null
},
{
"kind": "ClientExtension",
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "__id",
"storageKey": null
}
]
}
],
"storageKey": null
"storageKey": "organizations(first:25)"
},
{
"alias": null,
"args": (v1/*: any*/),
"filters": null,
"handle": "connection",
"key": "TeamSwitcher_organizations",
"kind": "LinkedHandle",
"name": "organizations"
},
{
"alias": null,
@@ -124,12 +213,12 @@ return {
]
},
"params": {
"cacheID": "48137f101a20a5ce116cbf46c2a8cd63",
"cacheID": "52b7d912665a4da10a79b82987a7e58a",
"id": null,
"metadata": {},
"name": "AppSidebarQuery",
"operationKind": "query",
"text": "query AppSidebarQuery {\n viewer {\n id\n ...TeamSwitcher_organizations\n ...NavUser_viewer\n }\n}\n\nfragment NavUser_viewer on User {\n id\n fullName\n email\n}\n\nfragment TeamSwitcher_organizations on User {\n organizations {\n id\n name\n logoUrl\n }\n}\n"
"text": "query AppSidebarQuery {\n viewer {\n id\n ...TeamSwitcher_organizations\n ...NavUser_viewer\n }\n}\n\nfragment NavUser_viewer on User {\n id\n fullName\n email\n}\n\nfragment TeamSwitcher_organizations on User {\n organizations(first: 25) {\n edges {\n node {\n id\n name\n logoUrl\n __typename\n }\n cursor\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n}\n"
}
};
})();

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<8ecb9304d0a498d483d1a8c251f8c49a>>
* @generated SignedSource<<a4a57a018956ccc09931f2b2ce87c933>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -11,11 +11,16 @@
import { ReaderFragment } from 'relay-runtime';
import { FragmentRefs } from "relay-runtime";
export type TeamSwitcher_organizations$data = {
readonly organizations: ReadonlyArray<{
readonly id: string;
readonly logoUrl: string;
readonly name: string;
}>;
readonly organizations: {
readonly __id: string;
readonly edges: ReadonlyArray<{
readonly node: {
readonly id: string;
readonly logoUrl: string;
readonly name: string;
};
}>;
};
readonly " $fragmentType": "TeamSwitcher_organizations";
};
export type TeamSwitcher_organizations$key = {
@@ -26,37 +31,121 @@ export type TeamSwitcher_organizations$key = {
const node: ReaderFragment = {
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"metadata": {
"connection": [
{
"count": null,
"cursor": null,
"direction": "forward",
"path": [
"organizations"
]
}
]
},
"name": "TeamSwitcher_organizations",
"selections": [
{
"alias": null,
"alias": "organizations",
"args": null,
"concreteType": "Organization",
"concreteType": "OrganizationConnection",
"kind": "LinkedField",
"name": "organizations",
"plural": true,
"name": "__TeamSwitcher_organizations_connection",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"concreteType": "OrganizationEdge",
"kind": "LinkedField",
"name": "edges",
"plural": true,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Organization",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "logoUrl",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "__typename",
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "cursor",
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"concreteType": "PageInfo",
"kind": "LinkedField",
"name": "pageInfo",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "endCursor",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "hasNextPage",
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "logoUrl",
"storageKey": null
"kind": "ClientExtension",
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "__id",
"storageKey": null
}
]
}
],
"storageKey": null
@@ -66,6 +155,6 @@ const node: ReaderFragment = {
"abstractKey": null
};
(node as any).hash = "318f68b82b5b87500ec99ffcdd2929ab";
(node as any).hash = "22731866cafda226a19f8c64fda51ba5";
export default node;

View File

@@ -73,7 +73,7 @@ function BreadcrumbFrameworkOverview() {
}
`,
{ frameworkId: frameworkId! },
{ fetchPolicy: "store-or-network" },
{ fetchPolicy: "store-or-network" }
);
return (
@@ -133,7 +133,7 @@ function BreadcrumbPeopleOverview() {
}
`,
{ peopleId: peopleId! },
{ fetchPolicy: "store-or-network" },
{ fetchPolicy: "store-or-network" }
);
return (
@@ -177,7 +177,7 @@ function BreadcrumbVendorOverview() {
}
`,
{ vendorId: vendorId! },
{ fetchPolicy: "store-or-network" },
{ fetchPolicy: "store-or-network" }
);
return (
@@ -215,7 +215,7 @@ function BreadcrumbControlOverview() {
}
`,
{ frameworkId: frameworkId!, controlId: controlId! },
{ fetchPolicy: "store-or-network" },
{ fetchPolicy: "store-or-network" }
);
return (
@@ -243,6 +243,20 @@ function BreadcrumbControlOverview() {
);
}
function BreadcrumbCreateOrganization() {
return (
<>
<BreadcrumbSeparator />
<BreadcrumbItem>
<BreadcrumbLink asChild>
<Link to="/organizations/create">Create Organization</Link>
</BreadcrumbLink>
</BreadcrumbItem>
<Outlet />
</>
);
}
export default function ConsoleLayout() {
return (
<SidebarProvider>
@@ -280,6 +294,10 @@ export default function ConsoleLayout() {
element={<BreadcrumbVendorOverview />}
/>
</Route>
<Route
path="/organizations/create"
element={<BreadcrumbCreateOrganization />}
/>
</Routes>
</BreadcrumbHome>
</div>

View File

@@ -0,0 +1,186 @@
import { useState } from "react";
import { useNavigate } from "react-router";
import {
graphql,
ConnectionHandler,
useMutation,
useLazyLoadQuery,
} from "react-relay";
import { Helmet } from "react-helmet-async";
import { Button } from "@/components/ui/button";
import { useOrganization } from "@/contexts/OrganizationContext";
import {
Card,
CardHeader,
CardTitle,
CardDescription,
CardContent,
} from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { useToast } from "@/hooks/use-toast";
import { HelpCircle } from "lucide-react";
import { CreateOrganizationPageCreateOrganizationMutation } from "./__generated__/CreateOrganizationPageCreateOrganizationMutation.graphql";
import { CreateOrganizationPageViewerQuery } from "./__generated__/CreateOrganizationPageViewerQuery.graphql";
const createOrganizationMutation = graphql`
mutation CreateOrganizationPageCreateOrganizationMutation(
$input: CreateOrganizationInput!
$connections: [ID!]!
) {
createOrganization(input: $input) {
organizationEdge @appendEdge(connections: $connections) {
node {
id
name
logoUrl
}
}
}
}
`;
const viewerQuery = graphql`
query CreateOrganizationPageViewerQuery {
viewer {
id
}
}
`;
function EditableField({
label,
value,
onChange,
type = "text",
helpText,
required,
}: {
label: string;
value: string;
onChange: (value: string) => void;
type?: string;
helpText?: string;
required?: boolean;
}) {
return (
<div className="space-y-2">
<div className="flex items-center gap-2">
<HelpCircle className="h-4 w-4 text-gray-400" />
<Label className="text-sm">{label}</Label>
</div>
<div className="space-y-2">
<Input
type={type}
value={value}
onChange={(e) => onChange(e.target.value)}
required={required}
/>
{helpText && <p className="text-sm text-gray-500">{helpText}</p>}
</div>
</div>
);
}
export default function CreateOrganizationPage() {
const navigate = useNavigate();
const { setCurrentOrganization } = useOrganization();
const data = useLazyLoadQuery<CreateOrganizationPageViewerQuery>(
viewerQuery,
{}
);
const [createOrganization] =
useMutation<CreateOrganizationPageCreateOrganizationMutation>(
createOrganizationMutation
);
const { toast } = useToast();
const [formData, setFormData] = useState({
name: "",
});
const handleFieldChange = (field: keyof typeof formData, value: string) => {
setFormData((prev) => ({
...prev,
[field]: value,
}));
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
createOrganization({
variables: {
input: {
name: formData.name,
},
connections: [
ConnectionHandler.getConnectionID(
data.viewer.id,
"TeamSwitcher_organizations"
),
],
},
onCompleted: (response) => {
const newOrg = response.createOrganization.organizationEdge.node;
setCurrentOrganization(newOrg);
toast({
title: "Success",
description: "Organization created successfully",
variant: "default",
});
navigate("/");
},
onError: (error) => {
toast({
title: "Error",
description: error.message || "Failed to create organization",
variant: "destructive",
});
},
});
};
return (
<>
<Helmet>
<title>Create Organization - Probo</title>
</Helmet>
<div className="container mx-auto p-6 space-y-6">
<div>
<h1 className="text-4xl font-medium tracking-tight">
Create Organization
</h1>
<p className="text-lg text-muted-foreground">
Create a new organization to manage your compliance and security
needs.
</p>
</div>
<form onSubmit={handleSubmit}>
<Card>
<CardHeader>
<CardTitle>Organization Details</CardTitle>
<CardDescription>
Enter the basic information about your organization.
</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
<EditableField
label="Organization Name"
value={formData.name}
onChange={(value) => handleFieldChange("name", value)}
helpText="The name of your organization as it will appear throughout the platform."
required
/>
<Button type="submit" className="w-full">
Create Organization
</Button>
</CardContent>
</Card>
</form>
</div>
</>
);
}

View File

@@ -13,104 +13,108 @@ export const HomePageQuery = graphql`
viewer {
id
organizations {
name
createdAt
updatedAt
vendors {
edges {
node {
id
name
createdAt
updatedAt
edges {
node {
name
createdAt
updatedAt
vendors {
edges {
node {
id
name
createdAt
updatedAt
}
}
}
}
}
peoples {
edges {
node {
id
fullName
primaryEmailAddress
additionalEmailAddresses
createdAt
updatedAt
peoples {
edges {
node {
id
fullName
primaryEmailAddress
additionalEmailAddresses
createdAt
updatedAt
}
}
}
}
}
frameworks {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
id
name
description
controls {
edges {
node {
id
name
state
stateTransisions {
edges {
node {
id
toState
fromState
createdAt
updatedAt
frameworks {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
id
name
description
controls {
edges {
node {
id
name
state
stateTransisions {
edges {
node {
id
toState
fromState
createdAt
updatedAt
}
}
}
}
}
tasks {
edges {
node {
id
name
state
evidences {
edges {
node {
id
state
fileUrl
stateTransisions {
edges {
node {
id
fromState
toState
reason
createdAt
updatedAt
tasks {
edges {
node {
id
name
state
evidences {
edges {
node {
id
state
fileUrl
stateTransisions {
edges {
node {
id
fromState
toState
reason
createdAt
updatedAt
}
}
}
createdAt
updatedAt
}
}
createdAt
updatedAt
}
stateTransisions {
edges {
node {
id
toState
fromState
reason
createdAt
updatedAt
}
}
}
createdAt
updatedAt
}
}
stateTransisions {
edges {
node {
id
toState
fromState
reason
createdAt
updatedAt
}
}
}
createdAt
updatedAt
}
}
}

View File

@@ -23,12 +23,13 @@ import {
useQueryLoader,
} from "react-relay";
import type { SettingsPageQuery as SettingsPageQueryType } from "./__generated__/SettingsPageQuery.graphql";
import { useOrganization } from "@/contexts/OrganizationContext";
const settingsPageQuery = graphql`
query SettingsPageQuery {
viewer {
query SettingsPageQuery($organizationID: ID!) {
organization: node(id: $organizationID) {
id
organizations {
... on Organization {
name
logoUrl
}
@@ -49,7 +50,7 @@ function SettingsPageContent({
queryRef: PreloadedQuery<SettingsPageQueryType>;
}) {
const data = usePreloadedQuery(settingsPageQuery, queryRef);
const organization = data.viewer.organizations[0];
const organization = data.organization;
const members: Member[] = [];
return (
@@ -216,9 +217,11 @@ export default function SettingsPage() {
const [queryRef, loadQuery] =
useQueryLoader<SettingsPageQueryType>(settingsPageQuery);
const { currentOrganization } = useOrganization();
useEffect(() => {
loadQuery({});
}, [loadQuery]);
loadQuery({ organizationID: currentOrganization!.id });
}, [loadQuery, currentOrganization]);
if (!queryRef) {
return <SettingsPageFallback />;

View File

@@ -0,0 +1,174 @@
/**
* @generated SignedSource<<75687d4b60d4ae79658fffb99ea6f52b>>
* @lightSyntaxTransform
* @nogrep
*/
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type CreateOrganizationInput = {
name: string;
};
export type CreateOrganizationPageCreateOrganizationMutation$variables = {
connections: ReadonlyArray<string>;
input: CreateOrganizationInput;
};
export type CreateOrganizationPageCreateOrganizationMutation$data = {
readonly createOrganization: {
readonly organizationEdge: {
readonly node: {
readonly id: string;
readonly logoUrl: string;
readonly name: string;
};
};
};
};
export type CreateOrganizationPageCreateOrganizationMutation = {
response: CreateOrganizationPageCreateOrganizationMutation$data;
variables: CreateOrganizationPageCreateOrganizationMutation$variables;
};
const node: ConcreteRequest = (function(){
var v0 = {
"defaultValue": null,
"kind": "LocalArgument",
"name": "connections"
},
v1 = {
"defaultValue": null,
"kind": "LocalArgument",
"name": "input"
},
v2 = [
{
"kind": "Variable",
"name": "input",
"variableName": "input"
}
],
v3 = {
"alias": null,
"args": null,
"concreteType": "OrganizationEdge",
"kind": "LinkedField",
"name": "organizationEdge",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Organization",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "logoUrl",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
};
return {
"fragment": {
"argumentDefinitions": [
(v0/*: any*/),
(v1/*: any*/)
],
"kind": "Fragment",
"metadata": null,
"name": "CreateOrganizationPageCreateOrganizationMutation",
"selections": [
{
"alias": null,
"args": (v2/*: any*/),
"concreteType": "CreateOrganizationPayload",
"kind": "LinkedField",
"name": "createOrganization",
"plural": false,
"selections": [
(v3/*: any*/)
],
"storageKey": null
}
],
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": [
(v1/*: any*/),
(v0/*: any*/)
],
"kind": "Operation",
"name": "CreateOrganizationPageCreateOrganizationMutation",
"selections": [
{
"alias": null,
"args": (v2/*: any*/),
"concreteType": "CreateOrganizationPayload",
"kind": "LinkedField",
"name": "createOrganization",
"plural": false,
"selections": [
(v3/*: any*/),
{
"alias": null,
"args": null,
"filters": null,
"handle": "appendEdge",
"key": "",
"kind": "LinkedHandle",
"name": "organizationEdge",
"handleArgs": [
{
"kind": "Variable",
"name": "connections",
"variableName": "connections"
}
]
}
],
"storageKey": null
}
]
},
"params": {
"cacheID": "aa445272c59c25a9a2edc7592c1fd7cc",
"id": null,
"metadata": {},
"name": "CreateOrganizationPageCreateOrganizationMutation",
"operationKind": "mutation",
"text": "mutation CreateOrganizationPageCreateOrganizationMutation(\n $input: CreateOrganizationInput!\n) {\n createOrganization(input: $input) {\n organizationEdge {\n node {\n id\n name\n logoUrl\n }\n }\n }\n}\n"
}
};
})();
(node as any).hash = "ec0da70244afe2faa02b05ee418b829e";
export default node;

View File

@@ -0,0 +1,74 @@
/**
* @generated SignedSource<<91e1415ad0a7d8ee0ae2a8e212f42f19>>
* @lightSyntaxTransform
* @nogrep
*/
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type CreateOrganizationPageViewerQuery$variables = Record<PropertyKey, never>;
export type CreateOrganizationPageViewerQuery$data = {
readonly viewer: {
readonly id: string;
};
};
export type CreateOrganizationPageViewerQuery = {
response: CreateOrganizationPageViewerQuery$data;
variables: CreateOrganizationPageViewerQuery$variables;
};
const node: ConcreteRequest = (function(){
var v0 = [
{
"alias": null,
"args": null,
"concreteType": "User",
"kind": "LinkedField",
"name": "viewer",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
}
],
"storageKey": null
}
];
return {
"fragment": {
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "CreateOrganizationPageViewerQuery",
"selections": (v0/*: any*/),
"type": "Query",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": [],
"kind": "Operation",
"name": "CreateOrganizationPageViewerQuery",
"selections": (v0/*: any*/)
},
"params": {
"cacheID": "8bb495e88bada2ffda332ffbc11f3340",
"id": null,
"metadata": {},
"name": "CreateOrganizationPageViewerQuery",
"operationKind": "query",
"text": "query CreateOrganizationPageViewerQuery {\n viewer {\n id\n }\n}\n"
}
};
})();
(node as any).hash = "2341c7947749857243e9f492235dfd61";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<17467071cb25b3e291532a4fb9074d67>>
* @generated SignedSource<<f40d67f614a103849ba940fbd14f71af>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -16,115 +16,119 @@ export type HomePageQuery$variables = Record<PropertyKey, never>;
export type HomePageQuery$data = {
readonly viewer: {
readonly id: string;
readonly organizations: ReadonlyArray<{
readonly createdAt: any;
readonly frameworks: {
readonly edges: ReadonlyArray<{
readonly cursor: any;
readonly node: {
readonly controls: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly id: string;
readonly name: string;
readonly state: ControlState;
readonly stateTransisions: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly fromState: ControlState | null | undefined;
readonly id: string;
readonly toState: ControlState;
readonly updatedAt: any;
readonly organizations: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly frameworks: {
readonly edges: ReadonlyArray<{
readonly cursor: any;
readonly node: {
readonly controls: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly id: string;
readonly name: string;
readonly state: ControlState;
readonly stateTransisions: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly fromState: ControlState | null | undefined;
readonly id: string;
readonly toState: ControlState;
readonly updatedAt: any;
};
}>;
};
}>;
};
readonly tasks: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly evidences: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly fileUrl: string;
readonly id: string;
readonly state: EvidenceState;
readonly stateTransisions: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly fromState: EvidenceState | null | undefined;
readonly id: string;
readonly reason: string | null | undefined;
readonly toState: EvidenceState;
readonly updatedAt: any;
readonly tasks: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly evidences: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly fileUrl: string;
readonly id: string;
readonly state: EvidenceState;
readonly stateTransisions: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly fromState: EvidenceState | null | undefined;
readonly id: string;
readonly reason: string | null | undefined;
readonly toState: EvidenceState;
readonly updatedAt: any;
};
}>;
};
}>;
};
readonly updatedAt: any;
readonly updatedAt: any;
};
}>;
};
}>;
};
readonly id: string;
readonly name: string;
readonly state: TaskState;
readonly stateTransisions: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly fromState: TaskState | null | undefined;
readonly id: string;
readonly reason: string | null | undefined;
readonly toState: TaskState;
readonly updatedAt: any;
readonly id: string;
readonly name: string;
readonly state: TaskState;
readonly stateTransisions: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly fromState: TaskState | null | undefined;
readonly id: string;
readonly reason: string | null | undefined;
readonly toState: TaskState;
readonly updatedAt: any;
};
}>;
};
}>;
};
readonly updatedAt: any;
readonly updatedAt: any;
};
}>;
};
}>;
};
};
}>;
};
}>;
readonly description: string;
readonly id: string;
readonly name: string;
};
}>;
readonly pageInfo: {
readonly endCursor: any | null | undefined;
readonly hasNextPage: boolean;
readonly hasPreviousPage: boolean;
readonly startCursor: any | null | undefined;
};
readonly description: string;
readonly id: string;
readonly name: string;
};
}>;
readonly pageInfo: {
readonly endCursor: any | null | undefined;
readonly hasNextPage: boolean;
readonly hasPreviousPage: boolean;
readonly startCursor: any | null | undefined;
readonly name: string;
readonly peoples: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly additionalEmailAddresses: ReadonlyArray<string>;
readonly createdAt: any;
readonly fullName: string;
readonly id: string;
readonly primaryEmailAddress: string;
readonly updatedAt: any;
};
}>;
};
readonly updatedAt: any;
readonly vendors: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly id: string;
readonly name: string;
readonly updatedAt: any;
};
}>;
};
};
};
readonly name: string;
readonly peoples: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly additionalEmailAddresses: ReadonlyArray<string>;
readonly createdAt: any;
readonly fullName: string;
readonly id: string;
readonly primaryEmailAddress: string;
readonly updatedAt: any;
};
}>;
};
readonly updatedAt: any;
readonly vendors: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly createdAt: any;
readonly id: string;
readonly name: string;
readonly updatedAt: any;
};
}>;
};
}>;
}>;
};
};
};
export type HomePageQuery = {
@@ -624,17 +628,39 @@ return {
{
"alias": null,
"args": null,
"concreteType": "Organization",
"concreteType": "OrganizationConnection",
"kind": "LinkedField",
"name": "organizations",
"plural": true,
"plural": false,
"selections": [
(v1/*: any*/),
(v2/*: any*/),
(v3/*: any*/),
(v4/*: any*/),
(v5/*: any*/),
(v10/*: any*/)
{
"alias": null,
"args": null,
"concreteType": "OrganizationEdge",
"kind": "LinkedField",
"name": "edges",
"plural": true,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Organization",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
(v1/*: any*/),
(v2/*: any*/),
(v3/*: any*/),
(v4/*: any*/),
(v5/*: any*/),
(v10/*: any*/)
],
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
@@ -663,18 +689,40 @@ return {
{
"alias": null,
"args": null,
"concreteType": "Organization",
"concreteType": "OrganizationConnection",
"kind": "LinkedField",
"name": "organizations",
"plural": true,
"plural": false,
"selections": [
(v1/*: any*/),
(v2/*: any*/),
(v3/*: any*/),
(v4/*: any*/),
(v5/*: any*/),
(v10/*: any*/),
(v0/*: any*/)
{
"alias": null,
"args": null,
"concreteType": "OrganizationEdge",
"kind": "LinkedField",
"name": "edges",
"plural": true,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Organization",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
(v1/*: any*/),
(v2/*: any*/),
(v3/*: any*/),
(v4/*: any*/),
(v5/*: any*/),
(v10/*: any*/),
(v0/*: any*/)
],
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
@@ -684,16 +732,16 @@ return {
]
},
"params": {
"cacheID": "d40cf8a4787ed129284c566abd99fdaf",
"cacheID": "5a56fefd066703ca0ebac1ef3e9a7e1f",
"id": null,
"metadata": {},
"name": "HomePageQuery",
"operationKind": "query",
"text": "query HomePageQuery {\n viewer {\n id\n organizations {\n name\n createdAt\n updatedAt\n vendors {\n edges {\n node {\n id\n name\n createdAt\n updatedAt\n }\n }\n }\n peoples {\n edges {\n node {\n id\n fullName\n primaryEmailAddress\n additionalEmailAddresses\n createdAt\n updatedAt\n }\n }\n }\n frameworks {\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n edges {\n cursor\n node {\n id\n name\n description\n controls {\n edges {\n node {\n id\n name\n state\n stateTransisions {\n edges {\n node {\n id\n toState\n fromState\n createdAt\n updatedAt\n }\n }\n }\n tasks {\n edges {\n node {\n id\n name\n state\n evidences {\n edges {\n node {\n id\n state\n fileUrl\n stateTransisions {\n edges {\n node {\n id\n fromState\n toState\n reason\n createdAt\n updatedAt\n }\n }\n }\n createdAt\n updatedAt\n }\n }\n }\n stateTransisions {\n edges {\n node {\n id\n toState\n fromState\n reason\n createdAt\n updatedAt\n }\n }\n }\n createdAt\n updatedAt\n }\n }\n }\n }\n }\n }\n }\n }\n }\n id\n }\n }\n}\n"
"text": "query HomePageQuery {\n viewer {\n id\n organizations {\n edges {\n node {\n name\n createdAt\n updatedAt\n vendors {\n edges {\n node {\n id\n name\n createdAt\n updatedAt\n }\n }\n }\n peoples {\n edges {\n node {\n id\n fullName\n primaryEmailAddress\n additionalEmailAddresses\n createdAt\n updatedAt\n }\n }\n }\n frameworks {\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n edges {\n cursor\n node {\n id\n name\n description\n controls {\n edges {\n node {\n id\n name\n state\n stateTransisions {\n edges {\n node {\n id\n toState\n fromState\n createdAt\n updatedAt\n }\n }\n }\n tasks {\n edges {\n node {\n id\n name\n state\n evidences {\n edges {\n node {\n id\n state\n fileUrl\n stateTransisions {\n edges {\n node {\n id\n fromState\n toState\n reason\n createdAt\n updatedAt\n }\n }\n }\n createdAt\n updatedAt\n }\n }\n }\n stateTransisions {\n edges {\n node {\n id\n toState\n fromState\n reason\n createdAt\n updatedAt\n }\n }\n }\n createdAt\n updatedAt\n }\n }\n }\n }\n }\n }\n }\n }\n }\n id\n }\n }\n }\n }\n}\n"
}
};
})();
(node as any).hash = "e9da69d4e7095f003eb28bf51e7c399d";
(node as any).hash = "7a1699535af738f939d954a88c6daa9e";
export default node;

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<f2e46ea14241587a319e9a6af9072bb9>>
* @generated SignedSource<<9a5ce377f093c4bbbb2375aacc373fb0>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -9,14 +9,14 @@
// @ts-nocheck
import { ConcreteRequest } from 'relay-runtime';
export type SettingsPageQuery$variables = Record<PropertyKey, never>;
export type SettingsPageQuery$variables = {
organizationID: string;
};
export type SettingsPageQuery$data = {
readonly viewer: {
readonly organization: {
readonly id: string;
readonly organizations: ReadonlyArray<{
readonly logoUrl: string;
readonly name: string;
}>;
readonly logoUrl?: string;
readonly name?: string;
};
};
export type SettingsPageQuery = {
@@ -25,56 +25,65 @@ export type SettingsPageQuery = {
};
const node: ConcreteRequest = (function(){
var v0 = {
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "organizationID"
}
],
v1 = [
{
"kind": "Variable",
"name": "id",
"variableName": "organizationID"
}
],
v2 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
v1 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
v2 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "logoUrl",
"storageKey": null
v3 = {
"kind": "InlineFragment",
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "logoUrl",
"storageKey": null
}
],
"type": "Organization",
"abstractKey": null
};
return {
"fragment": {
"argumentDefinitions": [],
"argumentDefinitions": (v0/*: any*/),
"kind": "Fragment",
"metadata": null,
"name": "SettingsPageQuery",
"selections": [
{
"alias": null,
"args": null,
"concreteType": "User",
"alias": "organization",
"args": (v1/*: any*/),
"concreteType": null,
"kind": "LinkedField",
"name": "viewer",
"name": "node",
"plural": false,
"selections": [
(v0/*: any*/),
{
"alias": null,
"args": null,
"concreteType": "Organization",
"kind": "LinkedField",
"name": "organizations",
"plural": true,
"selections": [
(v1/*: any*/),
(v2/*: any*/)
],
"storageKey": null
}
(v2/*: any*/),
(v3/*: any*/)
],
"storageKey": null
}
@@ -84,49 +93,43 @@ return {
},
"kind": "Request",
"operation": {
"argumentDefinitions": [],
"argumentDefinitions": (v0/*: any*/),
"kind": "Operation",
"name": "SettingsPageQuery",
"selections": [
{
"alias": null,
"args": null,
"concreteType": "User",
"alias": "organization",
"args": (v1/*: any*/),
"concreteType": null,
"kind": "LinkedField",
"name": "viewer",
"name": "node",
"plural": false,
"selections": [
(v0/*: any*/),
{
"alias": null,
"args": null,
"concreteType": "Organization",
"kind": "LinkedField",
"name": "organizations",
"plural": true,
"selections": [
(v1/*: any*/),
(v2/*: any*/),
(v0/*: any*/)
],
"kind": "ScalarField",
"name": "__typename",
"storageKey": null
}
},
(v2/*: any*/),
(v3/*: any*/)
],
"storageKey": null
}
]
},
"params": {
"cacheID": "5a3f5c431e1f886a330d220fd33a33f3",
"cacheID": "1ff42392cdd403c92101dc9c5fb7ceda",
"id": null,
"metadata": {},
"name": "SettingsPageQuery",
"operationKind": "query",
"text": "query SettingsPageQuery {\n viewer {\n id\n organizations {\n name\n logoUrl\n id\n }\n }\n}\n"
"text": "query SettingsPageQuery(\n $organizationID: ID!\n) {\n organization: node(id: $organizationID) {\n __typename\n id\n ... on Organization {\n name\n logoUrl\n }\n }\n}\n"
}
};
})();
(node as any).hash = "cef332dd829051516fa47315c3a60d1f";
(node as any).hash = "60cdb8a35f7e5f58536101243b57e57c";
export default node;

View File

@@ -85,6 +85,16 @@ type PageInfo {
endCursor: CursorKey
}
type OrganizationConnection {
edges: [OrganizationEdge!]!
pageInfo: PageInfo!
}
type OrganizationEdge {
cursor: CursorKey!
node: Organization!
}
type Organization implements Node {
id: ID!
name: String!
@@ -342,13 +352,17 @@ type EvidenceStateTransition {
updatedAt: Datetime!
}
# Authentication types
type User {
type User implements Node {
id: ID!
fullName: String!
email: String!
organizations: [Organization!]! @goField(forceResolver: true)
organizations(
first: Int
after: CursorKey
last: Int
before: CursorKey
): OrganizationConnection! @goField(forceResolver: true)
createdAt: Datetime!
updatedAt: Datetime!
@@ -371,6 +385,12 @@ type Mutation {
createPeople(input: CreatePeopleInput!): CreatePeoplePayload!
updatePeople(input: UpdatePeopleInput!): People!
deletePeople(input: DeletePeopleInput!): DeletePeoplePayload!
createOrganization(
input: CreateOrganizationInput!
): CreateOrganizationPayload!
deleteOrganization(
input: DeleteOrganizationInput!
): DeleteOrganizationPayload!
}
input CreateVendorInput {
@@ -474,3 +494,19 @@ type DeleteVendorPayload {
type DeletePeoplePayload {
deletedPeopleId: ID!
}
input CreateOrganizationInput {
name: String!
}
input DeleteOrganizationInput {
organizationId: ID!
}
type CreateOrganizationPayload {
organizationEdge: OrganizationEdge!
}
type DeleteOrganizationPayload {
deletedOrganizationId: ID!
}

File diff suppressed because it is too large Load Diff

View File

@@ -27,3 +27,9 @@ func NewOrganization(o *coredata.Organization) *Organization {
UpdatedAt: o.UpdatedAt,
}
}
func NewOrganizationEdge(o *coredata.Organization) *OrganizationEdge {
return &OrganizationEdge{
Node: NewOrganization(o),
}
}

View File

@@ -59,6 +59,14 @@ type ControlStateTransitionEdge struct {
Node *ControlStateTransition `json:"node"`
}
type CreateOrganizationInput struct {
Name string `json:"name"`
}
type CreateOrganizationPayload struct {
OrganizationEdge *OrganizationEdge `json:"organizationEdge"`
}
type CreatePeopleInput struct {
OrganizationID gid.GID `json:"organizationId"`
FullName string `json:"fullName"`
@@ -88,6 +96,14 @@ type CreateVendorPayload struct {
VendorEdge *VendorEdge `json:"vendorEdge"`
}
type DeleteOrganizationInput struct {
OrganizationID gid.GID `json:"organizationId"`
}
type DeleteOrganizationPayload struct {
DeletedOrganizationID gid.GID `json:"deletedOrganizationId"`
}
type DeletePeopleInput struct {
PeopleID gid.GID `json:"peopleId"`
}
@@ -186,6 +202,16 @@ type Organization struct {
func (Organization) IsNode() {}
func (this Organization) GetID() gid.GID { return this.ID }
type OrganizationConnection struct {
Edges []*OrganizationEdge `json:"edges"`
PageInfo *PageInfo `json:"pageInfo"`
}
type OrganizationEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *Organization `json:"node"`
}
type PageInfo struct {
HasNextPage bool `json:"hasNextPage"`
HasPreviousPage bool `json:"hasPreviousPage"`
@@ -292,14 +318,17 @@ type UpdateVendorInput struct {
}
type User struct {
ID gid.GID `json:"id"`
FullName string `json:"fullName"`
Email string `json:"email"`
Organizations []*Organization `json:"organizations"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID gid.GID `json:"id"`
FullName string `json:"fullName"`
Email string `json:"email"`
Organizations *OrganizationConnection `json:"organizations"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (User) IsNode() {}
func (this User) GetID() gid.GID { return this.ID }
type Vendor struct {
ID gid.GID `json:"id"`
Name string `json:"name"`

View File

@@ -169,6 +169,30 @@ func (r *mutationResolver) DeletePeople(ctx context.Context, input types.DeleteP
}, nil
}
// CreateOrganization is the resolver for the createOrganization field.
func (r *mutationResolver) CreateOrganization(ctx context.Context, input types.CreateOrganizationInput) (*types.CreateOrganizationPayload, error) {
organization, err := r.proboSvc.CreateOrganization(ctx, probo.CreateOrganizationRequest{
Name: input.Name,
})
if err != nil {
return nil, fmt.Errorf("cannot create organization: %w", err)
}
err = r.usrmgrSvc.AddUserToOrganization(ctx, UserFromContext(ctx).ID, organization.ID)
if err != nil {
return nil, fmt.Errorf("cannot add user to organization: %w", err)
}
return &types.CreateOrganizationPayload{
OrganizationEdge: types.NewOrganizationEdge(organization),
}, nil
}
// DeleteOrganization is the resolver for the deleteOrganization field.
func (r *mutationResolver) DeleteOrganization(ctx context.Context, input types.DeleteOrganizationInput) (*types.DeleteOrganizationPayload, error) {
panic(fmt.Errorf("not implemented: DeleteOrganization - deleteOrganization"))
}
// Frameworks is the resolver for the frameworks field.
func (r *organizationResolver) Frameworks(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.FrameworkConnection, error) {
cursor := types.NewCursor(first, after, last, before)
@@ -300,29 +324,35 @@ func (r *taskResolver) Evidences(ctx context.Context, obj *types.Task, first *in
}
// Organizations is the resolver for the organizations field.
func (r *userResolver) Organizations(ctx context.Context, obj *types.User) ([]*types.Organization, error) {
func (r *userResolver) Organizations(ctx context.Context, obj *types.User, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.OrganizationConnection, error) {
// Get the user's organization IDs
organizationIDs, err := r.usrmgrSvc.GetUserOrganizations(ctx, obj.ID)
if err != nil {
return nil, fmt.Errorf("failed to get user organizations: %w", err)
}
// If the user doesn't have any organizations, return an empty slice
// If the user doesn't have any organizations, return an empty connection
if len(organizationIDs) == 0 {
return []*types.Organization{}, nil
return &types.OrganizationConnection{
Edges: []*types.OrganizationEdge{},
PageInfo: &types.PageInfo{},
}, nil
}
// Get the organization details for each organization ID
var organizations []*types.Organization
var edges []*types.OrganizationEdge
for _, organizationID := range organizationIDs {
organization, err := r.proboSvc.GetOrganization(ctx, organizationID)
if err != nil {
return nil, fmt.Errorf("failed to get organization details: %w", err)
}
organizations = append(organizations, types.NewOrganization(organization))
edges = append(edges, types.NewOrganizationEdge(organization))
}
return organizations, nil
return &types.OrganizationConnection{
Edges: edges,
PageInfo: &types.PageInfo{},
}, nil
}
// Control returns schema.ControlResolver implementation.

View File

@@ -29,7 +29,7 @@ type (
Organization struct {
ID gid.GID
Name string
LogoURL string
LogoURL string
CreatedAt time.Time
UpdatedAt time.Time
}
@@ -82,3 +82,33 @@ LIMIT 1;
return nil
}
func (o *Organization) Insert(
ctx context.Context,
conn pg.Conn,
) error {
q := `
INSERT INTO organizations (
id,
name,
logo_url,
created_at,
updated_at
) VALUES (@id, @name, @logo_url, @created_at, @updated_at)
`
args := pgx.NamedArgs{
"id": o.ID,
"name": o.Name,
"logo_url": o.LogoURL,
"created_at": o.CreatedAt,
"updated_at": o.UpdatedAt,
}
_, err := conn.Exec(ctx, q, args)
if err != nil {
return err
}
return nil
}

View File

@@ -0,0 +1,66 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package probo
import (
"context"
"fmt"
"time"
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/probo/coredata"
"go.gearno.de/kit/pg"
)
type (
CreateOrganizationRequest struct {
Name string
}
)
func (s Service) CreateOrganization(
ctx context.Context,
req CreateOrganizationRequest,
) (*coredata.Organization, error) {
now := time.Now()
organizationID, err := gid.NewGID(coredata.OrganizationEntityType)
if err != nil {
return nil, fmt.Errorf("cannot create organization global id: %w", err)
}
organization := &coredata.Organization{
ID: organizationID,
Name: req.Name,
CreatedAt: now,
UpdatedAt: now,
}
err = s.pg.WithConn(
ctx,
func(conn pg.Conn) error {
if err := organization.Insert(ctx, conn); err != nil {
return fmt.Errorf("cannot insert control: %w", err)
}
return nil
},
)
if err != nil {
return nil, err
}
return organization, nil
}