-
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.
Merge pull request #42 from hubcio2115/feat/41-przy-rejestracji-uytko…
…wnikowi-powinna-tworzy-si-organizacja-pod-nazw-jego-nazwy-uytkownika Added a organization creation when user creates an account
- Loading branch information
Showing
10 changed files
with
1,634 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
import { generateSeedForOrgName } from "../utils"; | ||
|
||
test("is generated seed a whole number", () => { | ||
const value = generateSeedForOrgName(); | ||
|
||
expect(value % 1).lt(Number.EPSILON); | ||
}); | ||
|
||
test("is generated seed a 4 digit number", () => { | ||
const value = generateSeedForOrgName(); | ||
|
||
expect(value).gte(1000); | ||
expect(value).lt(10000); | ||
}); |
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,21 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
import { stripSpecialCharacters } from "../utils"; | ||
|
||
test('stripSpecialCharacters for "xx__Pu$$yD€$stroy€r__xx" return "xxPyDstroyrxx"', () => { | ||
const testingValue = stripSpecialCharacters("xx__Pu$$yD€$stroy€r__xx"); | ||
|
||
expect(testingValue).toBe("xxPuyDstroyrxx"); | ||
}); | ||
|
||
test('stripSpecialCharacters for "hubcio2115" leaves it alone', () => { | ||
const testingValue = stripSpecialCharacters("hubcio2115"); | ||
|
||
expect(testingValue).toBe("hubcio2115"); | ||
}); | ||
|
||
test('stripSpecialCharacters for "k-lisowski" leaves it alone', () => { | ||
const testingValue = stripSpecialCharacters("k-lisowski"); | ||
|
||
expect(testingValue).toBe("k-lisowski"); | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,24 @@ | ||
import { type ClassValue, clsx } from "clsx"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
export function cn(...inputs: ClassValue[]): string { | ||
return twMerge(clsx(inputs)); | ||
} | ||
|
||
/** | ||
* Strip a string of special characters other than "-" | ||
* @example | ||
* stripSpecialCharacters("xx__Pu$$yD€$stroy€r__xx"); // returns "xxPuyDstroyrxx" | ||
* @example | ||
* stripSpecialCharacters("hubcio2115"); // returns "hubcio2115" | ||
* @example | ||
* stripSpecialCharacters("k-lisowski"); // returns "k-lisowski" | ||
*/ | ||
export function stripSpecialCharacters(str: string): string { | ||
return str.replace(/[^a-zA-Z0-9-]/g, ""); | ||
} | ||
|
||
/** Generate a 4 digit seed number for unique organization names */ | ||
export function generateSeedForOrgName(): number { | ||
return Math.floor(Math.random() * 10000); | ||
} |
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
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,25 @@ | ||
"use server"; | ||
import "server-only"; | ||
|
||
import { eq } from "drizzle-orm"; | ||
|
||
import type { DbConnection } from "."; | ||
import { organizations } from "./schema"; | ||
|
||
export async function createOrganization( | ||
db: DbConnection, | ||
name: string, | ||
ownerId: string, | ||
) { | ||
return db.insert(organizations).values({ name, owner: ownerId }).returning(); | ||
} | ||
|
||
export async function getOrganizationByName(db: DbConnection, name: string) { | ||
return db | ||
.select({ | ||
id: organizations.id, | ||
name: organizations.name, | ||
}) | ||
.from(organizations) | ||
.where(eq(organizations.name, name)); | ||
} |
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,9 @@ | ||
import react from "@vitejs/plugin-react"; | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
plugins: [react()], | ||
test: { | ||
environment: "jsdom", | ||
}, | ||
}); |
Oops, something went wrong.