Skip to content

Commit

Permalink
Backend Additions and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VulpoTheDev committed Feb 11, 2023
1 parent 76fdf31 commit 9d2a8d2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 0 additions & 1 deletion api/.env.dev

This file was deleted.

17 changes: 11 additions & 6 deletions api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ model Fursona {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @db.VarChar(255)
species String
colors String[]
biography String? @default("I do not have a biography set at this time") @db.VarChar(2000)
sexuality String? @default("None") @db.VarChar(100)
gender String? @default("None") @db.VarChar(100)
Expand All @@ -25,14 +27,17 @@ model Fursona {

model Profile {
id Int @id @default(autoincrement())
bio String? @default("I have not created a bio")
fursonas Fursona[]
biography String? @default("I have not created a bio")
fursonas Fursona[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
artwork Artwork[]
username String @unique
email String @unique
password String @unique @default(cuid())
username String @unique
likes Int @default(0)
status String? @default("No Status")
email String @unique
password String @unique @default(cuid())
age Int
}

model Flags {
Expand All @@ -49,4 +54,4 @@ model Artwork {
fursonaId Int
owner Profile @relation(fields: [ownerId], references: [id])
ownerId Int
}
}
2 changes: 1 addition & 1 deletion api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "reflect-metadata"
import express from "express"
import routes from "./routes/index"
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
const prisma = new PrismaClient
import { ApolloServer } from "apollo-server-express"
import { buildSchema } from "type-graphql"
import { HelloResolver, ProfileResolver } from "./resolvers/"
Expand Down
13 changes: 11 additions & 2 deletions api/src/resolvers/ProfileResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class Profile {
username: string
@Field()
bio: string
@Field(() => Int)
age: number
@Field(() => Int)
likes: number
@Field()
status: string
@Field()
createdAt: Date
@Field()
Expand All @@ -52,7 +58,8 @@ export class ProfileResolver {

@Query(() => Profile)
async getProfileByUsername(@Arg("username", () => String) username: string) {
const profile = prisma.profile.findFirst({
username = username.toLowerCase()
const profile = await prisma.profile.findFirst({
where: {
username: username,
},
Expand All @@ -64,14 +71,16 @@ export class ProfileResolver {
async register(
@Arg("username", () => String) username: string,
@Arg("email", () => String) email: string,
@Arg("password", () => String) password: string
@Arg("password", () => String) password: string,
@Arg("age", () => Int) age: number
) {
const hashedPassword = await bcrypt.hash(password, 12)
const profile = await prisma.profile.create({
data: {
email,
username,
password: hashedPassword,
age: age,
id: randomInt(999999),
},
})
Expand Down

0 comments on commit 9d2a8d2

Please sign in to comment.