diff --git a/.env.example b/.env.example index f306c51..6e0fd0d 100644 --- a/.env.example +++ b/.env.example @@ -21,10 +21,6 @@ NEXT_PUBLIC_APPWRITE_ENDPOINT="" NEXT_PUBLIC_APPWRITE_PROJECT_ID="" APPWRITE_API_KEY="" -# Appwrite optional variables +# Prisma required variables -NEXT_PUBLIC_APPWRITE_DATABASE_ID="" -NEXT_PUBLIC_APPWRITE_COLLECTION_ID="" -NEXT_PUBLIC_APPWRITE_ADMIN_TEAM_ID="" -NEXT_PUBLIC_APPWRITE_ADMIN_MODERATOR_TEAM_ID="" -NEXT_PUBLIC_APPWRITE_ADMIN_COLLABORATOR_TEAM_ID="" \ No newline at end of file +DATABASE_URL="" \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index 8b9f981..0a7a2b0 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 94cab45..612d7c1 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@fortawesome/free-solid-svg-icons": "^6.5.1", "@fortawesome/react-fontawesome": "^0.2.0", "appwrite": "^13.0.1", + "entgamers-database": "^0.0.5", "entgamers-panda-preset": "0.1.0", "formik": "^2.4.5", "framer-motion": "^10.16.16", diff --git a/src/app/equipo/unirse/ApplyForm.tsx b/src/app/equipo/unirse/ApplyForm.tsx index 78d05a3..a8585a5 100644 --- a/src/app/equipo/unirse/ApplyForm.tsx +++ b/src/app/equipo/unirse/ApplyForm.tsx @@ -5,7 +5,6 @@ import Typography from '@/components/ui/Typography' import FormGroup from '@/components/ui/form/FormGroup' import Input from '@/components/ui/form/Input' import TextArea from '@/components/ui/form/TextArea' -import { createTeamApply } from '@/services/frontend/teamApply' import { css } from '@/styled-system/css' import { type Alert as AlertType } from '@/types/feedback' import { type TeamApplyData } from '@/types/teamApply' @@ -29,9 +28,9 @@ const ApplyForm: FC = () => { message: '', role: 'administrator' }, - onSubmit: async (values) => { + onSubmit: async (_values) => { try { - await createTeamApply(values) + // await createTeamApply(values) } catch (error) { if (error instanceof AppwriteException) { setAlert({ diff --git a/src/lib/appwrite.ts b/src/lib/appwrite.ts deleted file mode 100644 index 8e7be23..0000000 --- a/src/lib/appwrite.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Client, Databases } from 'appwrite' - -export const appwriteClient = new Client() - .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT ?? '') - .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT ?? '') - -export const databases = new Databases(appwriteClient) - -export { ID } from 'appwrite' diff --git a/src/lib/nodeAppwrite.ts b/src/lib/nodeAppwrite.ts deleted file mode 100644 index 2d09cf0..0000000 --- a/src/lib/nodeAppwrite.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Client, Databases, Teams } from 'node-appwrite' - -export const clientNodeAppwrite = new Client() - .setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT ?? '') - .setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID ?? '') - .setKey(process.env.APPWRITE_API_KEY ?? '') - -export const databases = new Databases(clientNodeAppwrite) - -export const teams = new Teams(clientNodeAppwrite) - -export { Permission, Role } from 'node-appwrite' diff --git a/src/services/backend/database.ts b/src/services/backend/database.ts deleted file mode 100644 index 63c627c..0000000 --- a/src/services/backend/database.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { databases } from '@/lib/nodeAppwrite' - -export const DATABASE_NAME = 'entgamers-website' -export const DATABASE_ID = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID ?? DATABASE_NAME - -export const ensureDatabase = (() => { - let databaseEnsured = false - return async () => { - if (databaseEnsured) return - try { - await databases.get(DATABASE_ID) - } catch (error) { - await databases.create(DATABASE_ID, DATABASE_NAME) - } finally { - databaseEnsured = true - } - } -})() diff --git a/src/services/backend/roles.ts b/src/services/backend/roles.ts deleted file mode 100644 index 00f31ad..0000000 --- a/src/services/backend/roles.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { teams } from '@/lib/nodeAppwrite' -import { type UserPreferences } from '@/types/User' - -export const ADMIN_TEAM_NAME = 'admin' -export const ADMIN_TEAM_ID = process.env.NEXT_PUBLIC_APPWRITE_ADMIN_TEAM_ID ?? ADMIN_TEAM_NAME -export const MODERATOR_TEAM_NAME = 'moderator' -export const MODERATOR_TEAM_ID = process.env.NEXT_PUBLIC_APPWRITE_MODERATOR_TEAM_ID ?? MODERATOR_TEAM_NAME -export const COLLABORATOR_TEAM_NAME = 'collaborator' -export const COLLABORATOR_TEAM_ID = process.env.NEXT_PUBLIC_APPWRITE_COLLABORATOR_TEAM_ID ?? COLLABORATOR_TEAM_NAME - -const ensureRoleExists = (roleId: string, roleName: string): (() => Promise) => { - let roleExists = false - return async (): Promise => { - if (roleExists) return - try { - await teams.get(roleId) - roleExists = true - } catch (error) { - await teams.create(roleId, roleName) - roleExists = true - } - } -} - -export const ensureRoles = async (): Promise => { - const adminRole = ensureRoleExists(ADMIN_TEAM_ID, ADMIN_TEAM_NAME) - const moderatorRole = ensureRoleExists(MODERATOR_TEAM_ID, MODERATOR_TEAM_NAME) - const collaboratorRole = ensureRoleExists(COLLABORATOR_TEAM_ID, COLLABORATOR_TEAM_NAME) - - await Promise.all([ - adminRole(), - moderatorRole(), - collaboratorRole() - ]) -} diff --git a/src/services/backend/teamApply.ts b/src/services/backend/teamApply.ts deleted file mode 100644 index bedfd68..0000000 --- a/src/services/backend/teamApply.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Permission, Role, databases } from '@/lib/nodeAppwrite' -import { DATABASE_ID, ensureDatabase } from '@/services/backend/database' -import { ADMIN_TEAM_ID } from './roles' - -export const TEAM_APPLY_COLLECTION_NAME = 'team-apply' -export const TEAM_APPLY_COLLECTION_ID = process.env.NEXT_PUBLIC_APPWRITE_TEAM_APPLY_COLLECTION_ID ?? TEAM_APPLY_COLLECTION_NAME - -export const ensureTeamApplyCollection = (() => { - let collectionEnsured = false - return async () => { - if (collectionEnsured) return - await ensureDatabase() - try { - await databases.getCollection(DATABASE_ID, TEAM_APPLY_COLLECTION_ID) - } catch (error) { - const permissions = [ - Permission.create(Role.any()), - Permission.read(Role.team(ADMIN_TEAM_ID)), - Permission.update(Role.team(ADMIN_TEAM_ID)), - Permission.delete(Role.team(ADMIN_TEAM_ID)) - ] - await databases.createCollection(DATABASE_ID, TEAM_APPLY_COLLECTION_ID, TEAM_APPLY_COLLECTION_NAME, permissions, false, true) - await databases.createStringAttribute(DATABASE_ID, TEAM_APPLY_COLLECTION_ID, 'name', 128, true) - await databases.createEmailAttribute(DATABASE_ID, TEAM_APPLY_COLLECTION_ID, 'email', true) - await databases.createStringAttribute(DATABASE_ID, TEAM_APPLY_COLLECTION_ID, 'discordName', 128, true) - await databases.createStringAttribute(DATABASE_ID, TEAM_APPLY_COLLECTION_ID, 'role', 24, true) - await databases.createStringAttribute(DATABASE_ID, TEAM_APPLY_COLLECTION_ID, 'message', 4096, true) - } finally { - collectionEnsured = true - } - } -})() diff --git a/src/services/frontend/database.ts b/src/services/frontend/database.ts deleted file mode 100644 index 2257640..0000000 --- a/src/services/frontend/database.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const DATABASE_NAME = 'entgamers-website' -export const DATABASE_ID = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID ?? DATABASE_NAME diff --git a/src/services/frontend/teamApply.ts b/src/services/frontend/teamApply.ts deleted file mode 100644 index ded76a4..0000000 --- a/src/services/frontend/teamApply.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ID, databases } from '@/lib/appwrite' -import { DATABASE_ID } from '@/services/frontend/database' -import { type TeamApplyData, type TeamApplyDocument, type TeamApplyList } from '@/types/teamApply' - -export const TEAM_APPLY_COLLECTION_NAME = 'team-apply' -export const TEAM_APPLY_COLLECTION_ID = process.env.NEXT_PUBLIC_APPWRITE_TEAM_APPLY_COLLECTION_ID ?? TEAM_APPLY_COLLECTION_NAME - -export const createTeamApply = async (data: TeamApplyData): Promise => { - const createdTeamApply = await databases.createDocument(DATABASE_ID, TEAM_APPLY_COLLECTION_ID, ID.unique(), data) - return createdTeamApply -} - -export const getTeamApply = async (teamApplyId: string): Promise => { - const teamApply = await databases.getDocument(DATABASE_ID, TEAM_APPLY_COLLECTION_ID, teamApplyId) - return teamApply -} - -export const listTeamApply = async (): Promise => { - const teamApplyList = await databases.listDocuments(DATABASE_ID, TEAM_APPLY_COLLECTION_ID) - return teamApplyList -} - -export const deleteTeamApply = async (teamApplyId: string): Promise => { - await databases.deleteDocument(DATABASE_ID, TEAM_APPLY_COLLECTION_ID, teamApplyId) -}