Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
Sambo Chea | e65c30ee20 | ||
Sambo Chea | a6c295cdfc | ||
Sambo Chea | 5190435b68 | ||
Sambo Chea | 70f9e968d4 | ||
Sambo Chea | 5a7843f114 | ||
Sambo Chea | 2a4beb0029 | ||
Sambo Chea | a175b78612 | ||
Sambo Chea | eee4841c0b |
|
@ -4,7 +4,7 @@ name: ci
|
|||
|
||||
steps:
|
||||
- name: test
|
||||
image: node
|
||||
image: d.ctdn.net/node
|
||||
commands:
|
||||
- yarn
|
||||
- yarn migrate
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
|
@ -1,5 +1,7 @@
|
|||
# Prisam Starter
|
||||
[![Build Status](https://dci.osa.cubetiqs.com/api/badges/CUBETIQ/prisma-starter/status.svg)](https://dci.osa.cubetiqs.com/CUBETIQ/prisma-starter)
|
||||
|
||||
- Prisam
|
||||
- SQLite
|
||||
- TypeScript
|
||||
- Jest
|
||||
- Jest
|
||||
|
|
14
package.json
14
package.json
|
@ -3,12 +3,12 @@
|
|||
"license": "MIT",
|
||||
"main": "main.ts",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.20",
|
||||
"jest": "^26.6.3",
|
||||
"prisma": "2.18.0",
|
||||
"ts-jest": "^26.5.3",
|
||||
"ts-node": "9.1.1",
|
||||
"typescript": "4.2.3"
|
||||
"@types/jest": "^27.0.2",
|
||||
"jest": "^27.2.1",
|
||||
"prisma": "^3.1.1",
|
||||
"ts-jest": "^27.0.5",
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "^4.4.3"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "ts-node ./src/main.ts",
|
||||
|
@ -16,7 +16,7 @@
|
|||
"test": "jest --detectOpenHandles --forceExit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "2.18.0"
|
||||
"@prisma/client": "^3.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
|
|
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,20 @@
|
|||
-- RedefineTables
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_Profile" (
|
||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"bio" TEXT NOT NULL,
|
||||
"avatar" TEXT,
|
||||
"userId" INTEGER NOT NULL,
|
||||
"enabled" BOOLEAN NOT NULL DEFAULT true,
|
||||
CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Profile" ("avatar", "bio", "enabled", "id", "userId") SELECT "avatar", "bio", "enabled", "id", "userId" FROM "Profile";
|
||||
DROP TABLE "Profile";
|
||||
ALTER TABLE "new_Profile" RENAME TO "Profile";
|
||||
CREATE UNIQUE INDEX "Profile_userId_key" ON "Profile"("userId");
|
||||
PRAGMA foreign_key_check;
|
||||
PRAGMA foreign_keys=ON;
|
||||
|
||||
-- RedefineIndex
|
||||
DROP INDEX "User.email_unique";
|
||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
|
@ -4,8 +4,8 @@ import UserRequest from "../Model/UserRequest";
|
|||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
function isProfileExistByEmail(email: string) {
|
||||
const exist = prisma.profile.count({
|
||||
async function isProfileExistByEmail(email: string) {
|
||||
const exist = await prisma.profile.count({
|
||||
where: {
|
||||
user: {
|
||||
email: email,
|
||||
|
@ -13,7 +13,7 @@ function isProfileExistByEmail(email: string) {
|
|||
},
|
||||
});
|
||||
|
||||
return exist.then((c) => c > 0).catch((e) => 0);
|
||||
return exist > 0;
|
||||
}
|
||||
|
||||
async function findOneProfileByEmail(email: string) {
|
||||
|
@ -30,15 +30,15 @@ async function findOneProfileByEmail(email: string) {
|
|||
|
||||
return profile;
|
||||
}
|
||||
|
||||
function isExistByEmail(email: string) {
|
||||
const exist = prisma.user.count({
|
||||
|
||||
async function isExistByEmail(email: string) {
|
||||
const exist = await prisma.user.count({
|
||||
where: {
|
||||
email: email,
|
||||
},
|
||||
});
|
||||
|
||||
return exist.then((c) => c > 0).catch((e) => 0);
|
||||
return exist > 0;
|
||||
}
|
||||
|
||||
async function findOneByEmail(
|
||||
|
@ -59,7 +59,7 @@ async function findOneByEmail(
|
|||
}
|
||||
|
||||
async function createUser(request: UserRequest) {
|
||||
if (isExistByEmail(request.email)) {
|
||||
if (await isExistByEmail(request.email)) {
|
||||
return findOneByEmail(request.email);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ async function createUser(request: UserRequest) {
|
|||
}
|
||||
|
||||
async function createProfile(user: User, request: ProfileRequest) {
|
||||
if (isProfileExistByEmail(user.email)) {
|
||||
if (await isProfileExistByEmail(user.email)) {
|
||||
return findOneProfileByEmail(user.email);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,13 @@ describe("user", function () {
|
|||
const bio = "Software Developer";
|
||||
|
||||
// create user test
|
||||
it("createUser", async (done) => {
|
||||
it("createUser", (done) => {
|
||||
// create user
|
||||
await createUser({
|
||||
createUser({
|
||||
email: email,
|
||||
name: name,
|
||||
})
|
||||
.then(async (user) => {
|
||||
.then((user) => {
|
||||
if (user == null) {
|
||||
throw Error("user is null");
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ describe("user", function () {
|
|||
expect(name).toBe(user.name);
|
||||
|
||||
// create profile
|
||||
await createProfile(user, {
|
||||
createProfile(user, {
|
||||
bio: "Software Developer",
|
||||
})
|
||||
.then((profile) => {
|
||||
|
@ -50,8 +50,8 @@ describe("user", function () {
|
|||
});
|
||||
|
||||
// check user test
|
||||
it("checkUser", async (done) => {
|
||||
await findOneByEmail(email)
|
||||
it("checkUser", (done) => {
|
||||
findOneByEmail(email)
|
||||
.then((user) => {
|
||||
if (user == null) {
|
||||
throw Error("user is null");
|
||||
|
@ -66,8 +66,8 @@ describe("user", function () {
|
|||
});
|
||||
|
||||
// check profile included user test
|
||||
it("checkProfileUser", async (done) => {
|
||||
await findOneProfileByEmail(email)
|
||||
it("checkProfileUser", (done) => {
|
||||
findOneProfileByEmail(email)
|
||||
.then((profile) => {
|
||||
if (profile == null) {
|
||||
throw Error("profile is null");
|
||||
|
@ -83,8 +83,8 @@ describe("user", function () {
|
|||
});
|
||||
|
||||
// try to finish
|
||||
afterAll(async (done) => {
|
||||
await prisma.$disconnect();
|
||||
afterAll((done) => {
|
||||
prisma.$disconnect();
|
||||
|
||||
done();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user