jklink/src/app/service/link.service.ts

32 lines
807 B
TypeScript

import { Injectable } from "@angular/core";
import { environment } from "../../environments/environment";
import PocketBase, { RecordModel } from 'pocketbase';
import { Link } from "../models/link";
@Injectable({
providedIn: 'root'
})
export class LinkService {
private pb = new PocketBase(environment.POCKETBASE);
getLinks(): Promise<Link[]> {
return this.pb.collection<Link>('links').getFullList<Link>();
}
getLink(id: string): Promise<Link> {
return this.pb.collection('links').getOne<Link>(id);
}
deleteLink(id: string) {
this.pb.collection('links').delete(id);
}
createLink(link: any): Promise<RecordModel> {
return this.pb.collection('links').create({
'name': link.name,
'link': link.link,
'owner': this.pb.authStore.record?.id,
});
}
}