Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
export default nextConfig;
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.53.0",
"react-icons": "^5.3.0",
"sonner": "^1.5.0",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
Expand Down
50 changes: 47 additions & 3 deletions src/api/api_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import type PocketBase from 'pocketbase'
import type { RecordService } from 'pocketbase'

export enum Collections {
Applications = "applications",
Chats = "chats",
Company = "company",
Experience = "experience",
Messages = "messages",
Response = "response",
Resume = "resume",
Users = "users",
Expand Down Expand Up @@ -38,12 +41,30 @@ export type AuthSystemFields<T = never> = {

// Record types for each collection

export enum ApplicationsStatusOptions {
"created" = "created",
"accepted" = "accepted",
"archived" = "archived",
}
export type ApplicationsRecord = {
resume: RecordIdString
status: ApplicationsStatusOptions
vacancy: RecordIdString
}

export type ChatsRecord = {
is_group?: boolean
title?: string
users?: RecordIdString[]
}

export type CompanyRecord = {
description?: HTMLString
email?: string
field?: string
name?: string
phone?: string
user?: RecordIdString
vacansies?: RecordIdString[]
website?: string
}
Expand All @@ -52,10 +73,17 @@ export type ExperienceRecord = {
company_name?: string
description?: HTMLString
end_date?: IsoDateString
field?: RecordIdString
resume?: RecordIdString
start_date?: IsoDateString
}

export type MessagesRecord = {
attachments?: string[]
chat?: RecordIdString
text: string
user?: RecordIdString
}

export type ResponseRecord = {
resume?: RecordIdString
vacancy?: RecordIdString
Expand All @@ -79,13 +107,15 @@ export enum ResumeEmploymentTypeOptions {
}
export type ResumeRecord = {
about?: HTMLString
age?: number
city?: string
education?: string
education_levels?: ResumeEducationLevelsOptions
email?: string
employment_type?: ResumeEmploymentTypeOptions
experience?: RecordIdString[]
full_name?: string
img?: string
phone_number?: string
salary?: number
skills?: string
Expand All @@ -97,9 +127,11 @@ export enum UsersRoleOptions {
}
export type UsersRecord = {
avatar?: string
chats?: RecordIdString[]
company?: RecordIdString
messages?: RecordIdString[]
resume?: RecordIdString
role?: UsersRoleOptions
role: UsersRoleOptions
}

export enum VacancyExperienceOptions {
Expand Down Expand Up @@ -129,12 +161,15 @@ export type VacancyRecord = {
publication_date?: IsoDateString
remote?: boolean
skills?: string
title?: string
title: string
}

// Response types include system fields and match responses from the PocketBase API
export type ApplicationsResponse<Texpand = unknown> = Required<ApplicationsRecord> & BaseSystemFields<Texpand>
export type ChatsResponse<Texpand = unknown> = Required<ChatsRecord> & BaseSystemFields<Texpand>
export type CompanyResponse<Texpand = unknown> = Required<CompanyRecord> & BaseSystemFields<Texpand>
export type ExperienceResponse<Texpand = unknown> = Required<ExperienceRecord> & BaseSystemFields<Texpand>
export type MessagesResponse<Texpand = unknown> = Required<MessagesRecord> & BaseSystemFields<Texpand>
export type ResponseResponse<Texpand = unknown> = Required<ResponseRecord> & BaseSystemFields<Texpand>
export type ResumeResponse<Texpand = unknown> = Required<ResumeRecord> & BaseSystemFields<Texpand>
export type UsersResponse<Texpand = unknown> = Required<UsersRecord> & AuthSystemFields<Texpand>
Expand All @@ -143,17 +178,23 @@ export type VacancyResponse<Texpand = unknown> = Required<VacancyRecord> & BaseS
// Types containing all Records and Responses, useful for creating typing helper functions

export type CollectionRecords = {
applications: ApplicationsRecord
chats: ChatsRecord
company: CompanyRecord
experience: ExperienceRecord
messages: MessagesRecord
response: ResponseRecord
resume: ResumeRecord
users: UsersRecord
vacancy: VacancyRecord
}

export type CollectionResponses = {
applications: ApplicationsResponse
chats: ChatsResponse
company: CompanyResponse
experience: ExperienceResponse
messages: MessagesResponse
response: ResponseResponse
resume: ResumeResponse
users: UsersResponse
Expand All @@ -164,8 +205,11 @@ export type CollectionResponses = {
// https://github.com/pocketbase/js-sdk#specify-typescript-definitions

export type TypedPocketBase = PocketBase & {
collection(idOrName: 'applications'): RecordService<ApplicationsResponse>
collection(idOrName: 'chats'): RecordService<ChatsResponse>
collection(idOrName: 'company'): RecordService<CompanyResponse>
collection(idOrName: 'experience'): RecordService<ExperienceResponse>
collection(idOrName: 'messages'): RecordService<MessagesResponse>
collection(idOrName: 'response'): RecordService<ResponseResponse>
collection(idOrName: 'resume'): RecordService<ResumeResponse>
collection(idOrName: 'users'): RecordService<UsersResponse>
Expand Down
79 changes: 78 additions & 1 deletion src/api/resume.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,94 @@
"use server";
import { permanentRedirect } from "next/navigation";
import { pocketbase } from "./pocketbase";

export const getResume = async (id: string) => {
const pb = pocketbase();
const resume = await pb.collection("resume").getOne(id);
const resume = await pb.collection("resume").getOne(id, {
expand: "experience",
});
return resume;
};

export const getUserByResume = async (id: string) => {
const pb = pocketbase();
const user = await pb.collection("users").getFirstListItem(`resume="${id}"`);
return user;
}

export const getExperience = async (id: string) => {
const pb = pocketbase();
const experience = await pb.collection("experience").getFullList({
filter: `resume="${id}"`,
});
return experience;
}

export const getImgUrl = async (id: string) => {
try {
const pb = pocketbase();
const record = await pb.collection('resume').getOne(id);
const firstFilename = record.img[0];
const url = pb.files.getUrl(record, firstFilename);
// const url = pocketbase.records.getFileUrl(record, record.imageField);
return url;
} catch (error) {
console.log(error);
return null;
}
}

export const userToResume = async (userId: string, resume: string) => {
const pb = pocketbase();
const updatedUser = await pb.collection("users").update(userId, {
resume: resume,
});
return updatedUser;
};

export const resumeRedirect = async (resumeId: string) => {
const pb = pocketbase();
if (resumeId) {
permanentRedirect(`/resume/${resumeId}`);
}
};
export const createResume = async (resume: any) => {
const pb = pocketbase();

const data = await pb.collection("resume").create(resume);
return data;
};

export const createExperience = async (experiences: any) => {
const pb = pocketbase();

const experiencePromises = experiences.map(async (experience: any) => {
return await pb.collection("experience").create(experience);
});

const results = await Promise.all(experiencePromises);
return results;
};

export const createSingleExperience = async (
id: string,
company: string,
description: string,
startDate: string,
endDate: string
) => {
const pb = pocketbase();
const experience = {
id,
company,
description,
startDate,
endDate,
};
await pb.collection("experience").create(experience);
};


export const hasResume = async (userId: string) => {
const pb = pocketbase();
const resumes = await pb.collection("users").getList(1, 1, {
Expand Down
Loading